💙
In Org, out of the box, pressing C-c C-x C-l sends embedded latex snippets to your TeX compiler, stores the resulting images somewhere, and displays them inline. This requires the program dvipng to be installed. (I enabled dvisvgm as an experiment and because vector graphics make me feel good.) We can use \(\) to embed a snippet in Org, or use a \begin{env}\end{env} block. Example:
# beginning of file
#+latex_header: \newcommand{\R}{\mathbb{R}}
* Proof of \(\phi\)
Here's our proof that \(\phi\) holds for all real numbers:
Suppose \(\phi = \psi\). Then clearly for all \(r \in \R\),
\begin{align}
\phi(r) & = \psi(r) \\
& = \alpha(r + 1) \wedge \beta(r - 1) \\
\end{align}
holds. The result obviously follows trivially.
# end of file
With snippets rendered in my Emacs, here's how the file looks:
Notice:
latex_header are available to snippets.latex_header is loaded completely even for snippets. That means you can usepackage.I found the default sizes for snippets too small. Try:
(setopt org-format-latex-options (plist-put org-format-latex-options :scale 1.2))
I'm unsure whether any of the Markdown modes have a similar feature, but it wouldn't surprise me.
Most of my standalone LaTeX documents, which are few, are generated by Org's exporter. It has piles of documentation and has been written about in detail by the community.
Setting a default class gives great benefit for its ease. Try your version of:
(add-to-list
'org-latex-classes
'("myclass"
"\\DocumentMetadata{lang=en,tagging=on}
\\documentclass{article}
[DEFAULT-PACKAGES]
[PACKAGES]
\\setmainfont{ETBookOT}
\\setmathfont{Tex Gyre Schola Math}
\\author{Ty Kozic}
[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
Notice:
("\\section{%s}" . ...) cause headings not to be numbered by default.DocumentMetadata is related to the LaTeX team's ongoing and admirable accessibility efforts: a tagged PDF is one particularly amenable to screen readers and the like. Your LaTeX compiler might not support it or might require testphase=phase-III instead of tagging=on on older versions.ETBookOT from the local system. (As long as fontspec is a default package; see org-latex-default-packages-alist and the more-user-editable org-latex-packages-alist.)Then simply use
#+latex_class: myclass
near the beginning of your Org file.
TODO: Do preview snippets inherit settings and package imports of the class?
The LaTeX project recommends LuaLaTeX for all new documents for its accessibility and unicode features, probably among other reasons.
Try:
(setopt org-latex-compiler "lualatex")
Also make sure it's installed. More than this setting might be warranted. It works for me despite occasional snags. Heavier LaTeX users will probably want to do more homework.
I've seen people say Unicode math renders much better than otherwise. I have no clue, but I like Unicode in general, so I added this one day:
(setopt org-latex-packages-alist
'(("" "unicode-math" t ("lualatex"))))
This reads, if the active compiler is LuaLaTeX, load the package unicode-math. Its usepackage is added where the Org class template says "[PACKAGES]" above. Read the documentation of org-latex-packages-alist.
I rarely do this but I can say a few things.
C-c C-c is bound to tex-compile in TeX-mode buffers. It behaves strangely for me when I invoke it in a modified buffer, so save before recompiling.
Use a PDF viewer that can watch the filesystem and automatically refresh when you recompile. If you're using an Emacs-based PDF viewer, try auto-revert-mode (which is a good thing to know about it general).
I also love and strongly recommend skeleton, one of Emacs' built-in templating libraries. I use these all over the place by attaching them to abbrevs and attaching those abbrevs to hippie-expand. (I don't use abbrev-mode itself.) This probably deserves a page of its own, but the Info manual Autotype that ships with Emacs is a good place to start.
I find that Emacs' built-in auto-pair modes like electric-pair-mode doesn't play well with \(\) in Org mode. I just deal with it, but there must be a better way.
Perhaps you are disgruntled by the very inputting of LaTeX: all those $$\mathbb{K}_{ij^6}\;\text{;}$$s. Many Emacsers to the rescue, but I know very little about their efforts. See AucTeX and CDLaTeX. I hesitantly conjecture that Skeleton and Abbrev together Pareto-approximate their functionality. I am almost certainly wrong.