Tuesday, May 11, 2021

How to inlude R code and output, and writing LaTeX equations on Blogger

Including R code and output:

1) Copy code and/or output from R

2) Go to http://hilite.me/

3) Paste code and/or output in Source Code panel 

4) Select 'S' in language drop-down menu

5) Tick ''Line numbers' option if necessary

6) Click 'Highlight!'

7) Copy result from the HTML panel.

8) Put Blogger post on HTML view (upper-left, drop-down arrow next to pencil) and paste. 

9) Go back to writing view( upper-left, drop-down arrow next to pencil) and see result.

 

Writing LaTeX equations:

When writing a post on Blogger, click the drop-down arrow next to the pencil symbol in the top-left and select HTML view.

Copy-paste the following lines to the very start of the HTML code:

<head><script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js" type="text/javascript">
MathJax.Hub.Config({
 extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js"],
 jax: ["input/TeX", "output/HTML-CSS"],
 tex2jax: {
     inlineMath: [ ['$','$'], ["\\(","\\)"] ],
     displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
 },
 "HTML-CSS": { availableFonts: ["TeX"] }
});
</script></head>  

Now if you can write equations within the usual dollar signs. That is, typing:

$\alpha$

will read $\alpha$ (but not while you are writing the post; click 'Example' in the top-right to check whether it works as expected when viewing the post).