1

I apologise if this has already been asked but I have no idea what are the "#+XYZ" commands in org-mode even called, tags? keywords? macros? I have a private Latex class whose usual header looks like this,

\documentclass{homework}

\author{Musa Al`Khwarizmi}
\class{CS 3141: Prof. Kamil's Algorithm Analysis}
\date{\today}
\title{Homework Class Test}
\address{Bayt El-Hikmah}

I wanted to use it with org-mode and setup everything and tested with this document header,

#+LATEX_CLASS: homework
#+AUTHOR: Musa Al`Khwarizmi
#+CLASS: CS 3141: Prof. Kamil's Algorithm Analysis
#+DATE: \today
#+TITLE: Homework in Org-mode
#+ADDRESS: Bayt El-Hikmah

It got me this Latex document,

% Created 2020-06-14 Sun 20:17
% Intended LaTeX compiler: xelatex
\documentclass{homework}
\author{Musa Al`Khwarizmi}
\date{\today}
\title{Homework in Org-mode}

How can I make the #+CLASS: and #+ADDRESS: work so \class{...} and \address{...} are also included in the Latex document?

1

In order to use #+LATEX_CLASS: homework you must have added an entry to the variable org-latex-classes - otherwise you would have gotten an Unknown LaTeX class 'homework' error. Presumably you have already done this since you don't get that error.

To add things to the LaTeX preamble (the part before \begin{document} you need to use #+LATEX_HEADER. E.g. to include the class and address you would write

#+LATEX_HEADER: \class{CS 3141: Prof. Kamil's Algorithm Analysis}
#+LATEX_HEADER: \address{Bayt El-Hikmah}

That is simple and it works for LaTeX export (and only LaTeX export), but if it is enough for your purposes, I recommend it for its simplicity.

E.g the following .org file (I'm using article for the LaTeX class, since I have not defined homework):

#+LATEX_CLASS: article
#+AUTHOR: Musa Al`Khwarizmi
#+LATEX_HEADER: \class{CS 3141: Prof. Kamil's Algorithm Analysis}
#+DATE: \today
#+TITLE: Homework in Org-mode
#+ADDRESS: Bayt El-Hikmah
* test
test

generates the following .tex file:

% Created 2020-06-14 Sun 23:56
% Intended LaTeX compiler: pdflatex
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\class{CS 3141: Prof. Kamil's Algorithm Analysis}
\author{Musa Al`Khwarizmi}
\date{\today}
\title{Homework in Org-mode}
\hypersetup{
 pdfauthor={Musa Al`Khwarizmi},
 pdftitle={Homework in Org-mode},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 28.0.50 (Org mode 9.3.6)}, 
 pdflang={English}}
\begin{document}

\maketitle
\tableofcontents

\section{test}
\label{sec:orgc559bfd}
test
\end{document}

If you want to add e.g. a #+CLASS: keyword to Org mode, however, the journey is going to be rougher. There is nothing stopping you from adding it to your file: after all, Org mode files are text files and you can add anything you want to them. But Org mode does not know anything about the CLASS keyword. In contrast it knows keywords like #+AUTHOR: and there is machinery to process them. IOW, in order to be able to write

#+CLASS: whatever

and have the LaTeX exporter translate that to

 \class{whatever}

in the output file, you will need to modify the machinery to a) recognize the keyword and b) do the translation. That would involve modifying the file ox.el to add the CLASS keyword and then modifying all the exporter backends (e.g. ox-latex.el) to use the keyword and emit the correct translation. It is not difficult to do, but there are repercussions: although your modified Org mode should be able to process any files that somebody else gives you, nobody else will be able to process any files you give them that contain the CLASS keyword: all they can do is ignore it.

So unless you have good reasons to proceed otherwise, I would recommend that you use the #+LATEX_HEADER: keyword as explained above.

| improve this answer | |
  • I see, is there anyway I can at-least adjust the order so that the insertions done by LATEX_HEADER are after the author, date and title and not immediately after the \documentclass{homework}? – scribe Jun 15 at 3:27
  • The LATEX_HEADER stuff by default goes after all the standard \usepackage directives in the preamble, so they do not come immediately after \documentclass{...}, unless those package lists are empty (which should not happen). But they come before \author, \date and \title: that is not easily changeable. In general, I don't look at the TeX file so I don't really care about the order. Is there any reason (other than aesthetics) that you want the other order? – NickD Jun 15 at 3:52
  • I am trying to switch from writing latex code with my homework class to org-mode. But I am also trying to not change things a lot in case I have to switch back. Also, I am using [NO-DEFAULT-PACKAGES]. – scribe Jun 15 at 3:55
  • I added an example file and the LaTeX output to show the order. – NickD Jun 15 at 3:57
  • You are going to run into trouble without default packages: the LaTeX exporter assumes that certain packages are present and the compilation will fail if they are not. E.g. if you use _underlined_ text in your Org mode document, the ulem package will be required. – NickD Jun 15 at 4:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.