4

I would like to create this Latex template in org-mode :

\documentclass[french, 11pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[hidelinks]{hyperref}
\usepackage[ddmmyyyy]{datetime}
\usepackage{microtype}
\usepackage{antiqua}
\author{My Name}
\date{\today}
\renewcommand{\contentsname}{Table des matières}

So I have added this to my .emacs in order to not have any of the default packages, just the one I want, based on what I saw on this tutorial :

(require 'ox-latex)
(with-eval-after-load 'ox-latex
(add-to-list 'org-latex-classes
           '("koma-article"
             "\documentclass[french, 11pt]{scrartcl}
             \usepackage[utf8]{inputenc}
             \usepackage[T1]{fontenc}
             \usepackage{babel}
             \usepackage[hidelinks]{hyperref}
             \usepackage[ddmmyyyy]{datetime}
             \usepackage{microtype}
             \usepackage{antiqua}
             \author{My Name}
             \date{\today}
             \renewcommand{\contentsname}{Table des matières}
             [NO-DEFAULT-PACKAGES]
             [NO-PACKAGES]"
             ("\\section{%s}" . "\\section*{%s}")
             ("\\subsection{%s}" . "\\subsection*{%s}")
             ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
             ("\\paragraph{%s}" . "\\paragraph*{%s}")
             ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))

So that when I want to create a new document in org-mode I just have to put :

#+TITLE: My Title
#+LaTeX_CLASS: koma-article

However when I try to compile a document I get :Unknown LaTeX class 'koma-article'. I am not sure what I'm doing wrong here. Is there a way to load only these packages without having to specify then in the buffer using #+LATEX_HEADER: \usepackage ?

3
  • 2
    Are you sure about the code? All backslashes should be escaped, e.g. \\documentclass, \\usepackage. Otherwise you're going to end up with an error in your add-to-list call.
    – Zeta
    Commented Nov 23, 2020 at 3:52
  • Check the value of org-latex-classes with C-h v org-latex-classes RET. As @Zeta points out, you are probably not adding the entry.
    – NickD
    Commented Nov 23, 2020 at 6:01
  • @Zeta Thanks, you're right escaping all the backslashes worked. Sorry, I guess that what happens when you edit your config at 5 a.m ^^'
    – user30768
    Commented Nov 23, 2020 at 15:54

3 Answers 3

4

As mentioned in the comments above, the latex commands need to be escaped. so this should work as expected....

(add-to-list 'org-latex-classes
           '("koma-article"
             "\\documentclass[french, 11pt]{scrartcl}
             \\usepackage[utf8]{inputenc}
             \\usepackage[T1]{fontenc}
             \\usepackage{babel}
             \\usepackage[hidelinks]{hyperref}
             \\usepackage[ddmmyyyy]{datetime}
             \\usepackage{microtype}
             \\usepackage{antiqua}
             \\author{My Name}
             \\date{\\today}
             \\renewcommand{\\contentsname}{Table des matières}
             [NO-DEFAULT-PACKAGES]
             [NO-PACKAGES]"
             ("\\section{%s}" . "\\section*{%s}")
             ("\\subsection{%s}" . "\\subsection*{%s}")
             ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
             ("\\paragraph{%s}" . "\\paragraph*{%s}")
             ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
1

According with what you are describing, I would recommend you to escape all the backslashes (all the backslashes that appear between the "koma-article" and [NO-DEFAULT-PACKAGES]). Finally, you need to make sure that you have the Koma-Script ‘article’ class installed: https://www.ctan.org/pkg/scrartcl.

1

Another way is to have an own latex header file, and input it at the very beginning of your file.

   ("mybestreport"
           "\\input{/home/path/to/your/latex/header/header.tex}"
           ("\\chapter{%s}" . "\\chapter*{%s}")
           ("\\section{%s}" . "\\section*{%s}")
           ("\\subsection{%s}" . "\\subsection*{%s}")
           ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
           ("\\fourthsection{%s}" . "\\fourthsection*{%s}")
           ("\\fifthsection{%s}" . "\\fifthsection*{%s}")
           )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.