t3lp3rion · 2022-06-07 20:04
Hi, I need to write a paper with a custom cls, and wanted to use org mode to do it. Of course, my first attempt was unsuccessful, since org mode was not able to find the cls file (after using \``#+LATEX_CLASS: customcls`) , despite having the file in the same directory. After reading the docs and [https://www.reddit.com/r/emacs/comments/uomvik/org\_mode\_to\_latex\_using\_a\_cls\_file/](https://www.reddit.com/r/emacs/comments/uomvik/org_mode_to_latex_using_a_cls_file/) , I realized that I could just configure org mode to find the cls file by creating a new entry in my emacs config and copying the cls file inside the emacs config dir.
But I do not want to pollute my config with this. This is a single time to use this for a single conference.
Is it possible to configure the org file to evaluate some lisp code to add the custom cls to the org-latex-class list and set its path? I tried with no success using a \* COMMENT section and so on. For now, I am just using latex directly.
Thanks for any advice.
unbelievable_sc2 · 2022-06-07 20:36
You can of course create an emacs-lisp source code in the org more buffer and manually evaluate when you start editing the file. Alternatively you can create directly local variables ( https://www.emacswiki.org/emacs/DirectoryVariables ) to change the org variables for files in a given directly. Also the cls file does not have to be in the config dir, you can put it right next to the org file.
t3lp3rion · 2022-06-07 22:02
Hi, thanks for the suggestion. I tried it but still emacs says that it cannot find the class file, but it is in the same directory as the org file. Basically what I did:- Contents of .dirs-local.el:
`(add-to-list 'org-latex-classes '("llncs" " \\documentclass[runningheader]{llncs}"))`
Then I open the org file in emacs and try to export it to latex, then the error "Unknown LaTeX class llncs" appears. Am I doing something wrong?
t3lp3rion · 2022-06-07 22:19
Notice that I even used `add-dir-local-variable` to create a setting with eval , which produced the following code
`((org-mode . ((eval . (add-to-list 'org-latex-classes '("llncs" "\\documentclass[runningheader]{llncs}"))))))`
and yet the same error appears when exporting to latex: Unknown latex class llncs. I use doom emacs so actually I do not know where to put it (I tried both .emacs.d and .doom without any success)
unbelievable_sc2 · 2022-06-07 22:43
You have to use the correct syntax for the .dir-locals.el file. You cannot just put the elisp code there.
This works for me having the llncs.sty file in the same directory. The first time you open a file in this directory it will ask you if you consider it safe to change the variables. You can select to alwayst trust this variable and not be asked again.
.dir.locals.el
((org-mode
. ((org-latex-classes
. (("llncs" "\\documentclass[runningheads]{llncs}"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))))))
test.org
#+latex_class: llncs
#+title: test
* Section
hello
** world
lorem ipsum
t3lp3rion · 2022-06-08 22:24
>((org-mode
. ((org-latex-classes
. (("llncs" "\\\\documentclass\[runningheads\]{llncs}"
("\\\\section{%s}" . "\\\\section\*{%s}")
("\\\\subsection{%s}" . "\\\\subsection\*{%s}")
("\\\\subsubsection{%s}" . "\\\\subsubsection\*{%s}")
("\\\\paragraph{%s}" . "\\\\paragraph\*{%s}")
("\\\\subparagraph{%s}" . "\\\\subparagraph\*{%s}")))))))
Yes, it worked, many thanks!