Subfigures or Subcaptions with knitr?

knitr (>= v1.5) supports subfigures. You can use the chunk option fig.subcap. Here is a minimal example. \documentclass{article} \usepackage{subfig} \begin{document} <<fig-sub, fig.cap=’two plots’, fig.subcap=c(‘one plot’, ‘the other one’), out.width=”.49\\linewidth”>>= plot(1:10) plot(rnorm(10), pch=19) @ \end{document}

What is the best way to embed LaTeX in a webpage?

I prefer MathJax over solutions that choose to render images (which causes aliasing problems). MathJax is an open source Javascript rendering engine for mathematics. It uses CSS and Webfonts instead of images or flash and can render LaTeX or MathML. That way you don’t have problems with zoom and it’s even screenreader compatible.

Set margin size when converting from Markdown to PDF with pandoc

Recent versions of rmarkdown and pandoc In more recent versions of rmarkdown, the settings of margins can be done in the YAML header via the top-level element geometry. What you specify in the geometry tag will be piped into the LaTeX template that ships with Pandoc via the following LaTeX snippet $if(geometry)$ \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} $endif$ For … Read more

Sans-serif math with latex in matplotlib

I always have text.usetex = True in my matplotlibrc file. In addition to that, I use this as well: mpl.rcParams[‘text.latex.preamble’] = [ r’\usepackage{siunitx}’, # i need upright \micro symbols, but you need… r’\sisetup{detect-all}’, # …this to force siunitx to actually use your fonts r’\usepackage{helvet}’, # set the normal font here r’\usepackage{sansmath}’, # load up the … Read more

Generating pdf-latex with python script

You can start by defining the template tex file as a string: content = r”’\documentclass{article} \begin{document} … \textbf{\huge %(school)s \\} \vspace{1cm} \textbf{\Large %(title)s \\} … \end{document} ”’ Next, use argparse to accept values for the course, title, name and school: parser = argparse.ArgumentParser() parser.add_argument(‘-c’, ‘–course’) parser.add_argument(‘-t’, ‘–title’) parser.add_argument(‘-n’, ‘–name’,) parser.add_argument(‘-s’, ‘–school’, default=”My U”) A bit … Read more

How to write LaTeX in IPython Notebook?

IPython notebook uses MathJax to render LaTeX inside html/markdown. Just put your LaTeX math inside $$. $$c = \sqrt{a^2 + b^2}$$ Or you can display LaTeX / Math output from Python, as seen towards the end of the notebook tour: from IPython.display import display, Math, Latex display(Math(r’F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx’))

Getting LaTeX into R Plots

The CRAN package latex2exp contains a TeX function that translate LaTeX formulas to R’s plotmath expressions. You can use it anywhere you could enter mathematical annotations, such as axis labels, legend labels, and general text. For example: x <- seq(0, 4, length.out=100) alpha <- 1:5 plot(x, xlim=c(0, 4), ylim=c(0, 10), xlab=’x’, ylab=TeX(r'($\alpha x^\alpha$, where $\alpha … Read more