latex
How to convert HTML with mathjax into Latex using Pandoc?
With the latest version of pandoc (1.12.2), you can do this: pandoc -f html+tex_math_dollars+tex_math_single_backslash -t latex Much nicer! If you don’t want to convert math delimited by \( and \), just do pandoc -f html+tex_math_dollars -t latex
LaTeX package for syntax highlighting of code in various languages
You can use the listings package. It supports many different languages and there are lots of options for customising the output. \documentclass{article} \usepackage{listings} \begin{document} \begin{lstlisting}[language=html] <html> <head> <title>Hello</title> </head> <body>Hello</body> </html> \end{lstlisting} \end{document}
Get rid of \addlinespace in kable
You can add the argument linesep = “” to kable. This will be passed on to kable_latex where it overwrites the default linesep = if (booktabs) c(”, ”, ”, ”, ‘\\addlinespace’) else ‘\\hline’ Example: kable(cars, format = “latex”, booktabs = TRUE, linesep = “”)
Converting latex code to Images (or other displayble format) with Python
SymPy has a builtin preview function that does this. expr = sin(sqrt(x**2 + 20)) + 1 preview(expr, viewer=”file”, filename=”output.png”) generates There are lots of options to preview to change the format of the output (for instance, if you don’t like the Euler font you can set euler=False). preview also accepts a LaTeX string instead of … Read more
Code chunk font size in Rmarkdown with knitr and latex
Picking up the idea to alter a knitr hook we can do the following: def.chunk.hook <- knitr::knit_hooks$get(“chunk”) knitr::knit_hooks$set(chunk = function(x, options) { x <- def.chunk.hook(x, options) ifelse(options$size != “normalsize”, paste0(“\n \\”, options$size,”\n\n”, x, “\n\n \\normalsize”), x) }) This snippet modifies the default chunk hook. It simply checks if the chunk option size is not equal … Read more
Git merging within a line
Here’s a solution in the same vein as sehe’s, with a few changes which hopefully will address your comments: This solution considers merging by sentence rather than by word, as you had been doing by hand, only now, the user will see a single line per paragraph, but git will see paragraphs broken into sentences. … Read more
Latex rendering in README.md on Github
For short expresions and not so fancy math you could use the inline HTML to get your latex rendered math on codecogs and then embed the resulting image. Here an example: – <img src=”https://latex.codecogs.com/gif.latex?O_t=\text { Onset event at time bin } t ” /> – <img src=”https://latex.codecogs.com/gif.latex?s=\text { sensor reading } ” /> – <img … Read more
How to write your own LaTeX preamble in Matplotlib?
When I need to use LaTeX with matplotlib, I add the following to the python script (+ additional commands for debug info) import matplotlib.pyplot as plt plt.rc(‘text’, usetex=True) plt.rc(‘text.latex’, preamble=r’\usepackage{amsmath} \usepackage{foo-name} `…’) matplotlib.verbose.level=”debug-annoying” commands to make your plot here
Align multiple tables side by side
Just put two data frames in a list, e.g. t1 <- head(mtcars)[1:3] t2 <- head(mtcars)[4:6] knitr::kable(list(t1, t2)) Note this requires knitr >= 1.13.