reddit / emacs

Org mode to latex using a .cls file.

ntwmbc · 2022-05-13 08:12
Hello, my university requires me to use their custom (and worse than default...) latex template for my thesis. Adding custom classes to org mode is documented in several places: https://rgoswami.me/posts/org-arb-tex/#latex-classes However, all that I see require more work than just saying "please use template.cls for export." The template I have to work with is over 700 lines long, and to either manually translate it to a format such as https://rgoswami.me/posts/org-arb-tex/#latex-classes or create a new program to do the conversion, is likely to cause inconsistencies or bugs. At least in the time span that I have available right now. Is there a way to tell org mode to just use a specific .cls file during latex export?
Deep-Fox6860 · 2022-05-13 12:18
Did you try adding `#+LATEX_CLASS: your_custom_class`, like is mentioned [here](https://orgmode.org/manual/LaTeX-header-and-sectioning.html)?
tsdwm52 · 2022-05-13 13:02
Check that your university template just redefines LaTeX standard commands and does not introduce new commands. If it does introduce new commands, then you'll need to teach Org mode how to export them, which can be done but is often difficult. If your university template just redefines standard commands, then adding a specification to org-latex-classes as shown by Goswami will work. You can put the specification in your .emacs, restart Emacs, and then follow u/Deep-Fox6860's recommendation. You don't have to translate the university template. If your university template introduces new LaTeX commands, then you are almost certainly better off writing your thesis in LaTeX. Good luck.
ntwmbc · 2022-05-13 13:09
From my understanding, that requires the class to be added to `org-latex-classes` similar to the current values: (("article" "\\documentclass[11pt]{article}" [...] Simply adding #+LATEX_CLASS: mytemplate # tried also with mytemplate.cls when `mytemplate.cls` is in the same folder as the org document results in "unknown latex class mytemplate"
ntwmbc · 2022-05-13 13:10
There are *many* new commands added... It's not that bad. I have a lot written in or right now but can easily port it to latex in a short amount of time. Thank you!
NoisyFrequency · 2022-05-13 13:29
Put the class file in the same directory as your `init.el` and in the `init.el`, write : (add-to-list 'org-latex-classes '("uni_template" " \\documentclass[]{<yourclsfile>}")) The `cls` file should be named without the `cls` extension so if it's `template.cls`, the above line should read `"\\documentclass[]{template}"` Now that this is done, you can use `#+latex_class: uni_template` in an org file. Note that in the code above, the first element of the list if the arbitrary name you give to the class, could've been "lemon_squeezy" as well. The following element is a string of what you'd usually find in top level declaration of a `.tex` file. For example, here is my custom note taking class. (add-to-list 'org-latex-classes '("notes" "\\documentclass[french, 12pt]{article} \\usepackage{minted} \\usepackage[round]{natbib} \\usepackage{babel} \\usepackage[utf8]{inputenc} \\usepackage[T1]{fontenc} \\usepackage{mathptmx} \\usepackage{booktabs} \\usepackage{longtable} \\usepackage[skip=1.\\baselineskip]{caption} \\usepackage{soul} \\usepackage[usenames,dvipsnames,svgnames]{xcolor} \\usepackage{parskip} \\usepackage[many]{tcolorbox} \\usepackage{hyperref} \\usepackage[export]{adjustbox} \\usepackage{subcaption} \\hypersetup{ colorlinks=true, linkcolor={PineGreen!50!black}, citecolor={Bittersweet!50!Sepia}, urlcolor={blue!80!black}} \\usepackage{geometry} \\geometry{a4paper,left=2.5cm,top=1.2cm,right=2.5cm,bottom=1.5cm,marginparsep=7pt, marginparwidth=.6in}" ("\\section{%s}" . "\\section*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
Pyroraptor42 · 2022-05-13 14:11
I confess that I actually haven't used Org mode, for LaTeX or otherwise, but I will say that the AUCTeX package for Emacs is phenomenal for writing LaTeX, with lots of autocorrect and preview options. I don't know if you'd want to switch, but it'll avoid a lot of the problems the other commenters have mentioned.
ntwmbc · 2022-05-14 19:33
That did it! Thank you. What a great time to be alive.