Recently I needed to generate PDF documents including mathematical formulae and graphics drawings. As I already use org-mode for documentation, I decided to employ org-mode for this task as well, rather than dealing with LaTeX directly, like I used to do a long time ago.
This page contains
You might want to download the file ./org2latex.zip to see my test and configuration files.
I use the "texlive" TeX/LaTeX software. I installed the following Debian packages:
texlive
texlive-latex-extra
wrapfig.sty
, which
is required by the org-mode exporter (Emacs v28.2 org-mode v9.5.5)cm-super
texlive-lang-german
texlive-latex-recommended-doc
inkscape
inkscape
automatically to support SVGI wanted to do as few tweaking on the LaTeX set-up as possible and hence tried to fulfil as many of my requirements on the org-mode side.
The org-mode exporter UI (C-c C-e
) gives you the choice to generate
a *.tex
or *.pdf
file (with *.tex
as an intermediate step). If
you choose the latter, the pdflatex
program will be invoked by
org-mode by default.
Instead of putting org-mode settings in Emacs' init.el
file, I put
them in a file mysetup.org
, which I include in a main.org
document
file like this:
#+SETUPFILE: ~/mysetup.org
as the first line. This allows for easy central maintenance.
And: If you needed a special setting for a particular document, you
could still put this setting after the #+SETUPFILE...
line and it
will take precedence.
Not all settings can be put in the set-up file. I needed to have LaTeX
import a file with symbol definitions, to have additional UTF-8
special characters available in LaTeX. Only the LaTeX import statement
could go in the org-mode set-up file. The LaTeX definitions went in
a file called myAddUTF8.tex
. I store this file in directory ~/texmf/
I share those files in file ./org2latex.zip, which contains:
README.txt | txt version of this web-page |
test.org | Test org-mode source file |
test.pdf | Resulting output PDF file |
test.tex | Resulting intermediate LaTeX file |
mysetup.org | Org set-up file |
myAddUTF8.tex | LaTeX symbol definitions |
redetho-logo1.svg | Test logo |
blind_*.svg | Test vector graphics file |
blind_*.jpg | Test image files |
lit.bib | Test BibTeX file for citations |
The files are provided as is. I do not take any responsibility nor provide any warranty.
mysetup.org
to your home directory. If you
choose a different location, please amend the path in the first line
of test.org
You might want to copy myAddUTF8.tex
to ~/texmf/
. If you choose
a different location, please amend the line
#+LATEX_HEADER: \input{~/texmf/myAddUTF8}
in file mysetup.org
test.org
in EmacsC-c C-e l p
, which runs
the command org-latex-export-to-pdf
test.pdf
using your favourite PDF-viewer.
Please note that the ZIP archive also contains a result file
test.pdf
and the intermediate file test.tex
for your reference.
You might want to rename those two beforehand
While the C-c C-e
standard org-mode exporter is fine for tests and
occasional exports, I use a Makefile for more complex projects. That
Makefile would typically contain (covers both Windows and Linux):
ifeq ($(OS),Windows_NT) EMACSCL=$(MYPROGPATH)/emacs-27.2/bin/emacsclientw.exe else EMACSCL=emacsclient endif test.pdf: test.org $(HOME)/mysetup.org $(EMACSCL) --eval "(find-file \"test.org\")" \ "(org-latex-export-to-pdf)"
Below text has some narrative about the LaTeX settings in file
mysetup.org
. Of course your requirements may be different.
#+LATEX_CLASS_OPTIONS: [a4paper,11pt]
You might have different paper or font size requirements
#+LATEX_HEADER: \usepackage[a4paper,margin=1in,left=1.5in]{geometry}
The default LaTeX page layout use quite a lot of margin, which I adjust here
# #+LATEX_HEADER: \usepackage{helvet}
Normally, I am fine with Computer Modern fonts for article type write-ups, but in case…
#+LATEX_HEADER: \usepackage[shorthands=off,english]{babel}
"babel" allows to use other languages in addition to english. This construct does two things:
#+LANGUAGE: xx
will be appropriately added by the org mode exporter to this
statement. Thus language xx becomes the "start" language in your
document. You could then switch to english using embedded LaTeX
constructs and back to XX. This can be expanded to more than two
languagesshorthands=off
switches this escape mechanism off. Because today
this escaping is much less needed as you can enter such characters
directly as UTF-8.#+LATEX_HEADER: \usepackage{eurosym}
The currency I use most often.
#+LATEX_HEADER: \usepackage{parskip}
I prefer to separate paragraphs by empty space rather than by indenting the first line.
#+LATEX_HEADER: \usepackage{svg}
I use scalable vector graphics (SVG)
#+OPTIONS: tex:dvisvgm
That part of mysetup.org
is related to SVG processing. It makes sure
that SVG files stay scalable rather than being converted to bit mapped
graphics.
#+LATEX_HEADER: \svgsetup{inkscapelatex=false}
By default, LaTeX processes text elements in the included SVG
files. This can produce unexpected results. inkscapelatex=false
lets
the text elements alone.
# UTF-8 input is fine, but for output LaTeX needs some definitions #+LATEX_HEADER: \input{~/texmf/myAddUTF8}
While you can use UTF-8 to input quite some special characters, LaTeX needs further definitions on the output side.
# Customise title #+LATEX_HEADER: \makeatletter #+LATEX_HEADER: \renewcommand{\maketitle}{% #+LATEX_HEADER: \begingroup\parindent0pt #+LATEX_HEADER: \sffamily #+LATEX_HEADER: \Huge{\bfseries\@title}\par\bigskip #+LATEX_HEADER: \LARGE{\bfseries\@author}\par\medskip #+LATEX_HEADER: \normalsize\@date\par\bigskip #+LATEX_HEADER: \endgroup\@afterindentfalse\@afterheading} #+LATEX_HEADER: \makeatother
These statements define a custom title page, where things are left aligned rather than centered.
I trust you notice that mysetup.org
also contains org-mode in-buffer
customisations for HTML export and text export. I have written
about HTML export here
You might also be interested in beamer slide generation from org-mode or using pandoc together with org-mode.