# How to define an org-mode "#+" type keyword?

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 AlKhwarizmi}
\class{CS 3141: Prof. Kamil's Algorithm Analysis}
\date{\today}
\title{Homework Class Test}


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

#+LATEX_CLASS: homework
#+AUTHOR: Musa AlKhwarizmi
#+CLASS: CS 3141: Prof. Kamil's Algorithm Analysis
#+DATE: \today
#+TITLE: Homework in Org-mode


It got me this Latex document,

% Created 2020-06-14 Sun 20:17
% Intended LaTeX compiler: xelatex
\documentclass{homework}
\author{Musa AlKhwarizmi}
\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?

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}


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 AlKhwarizmi
#+LATEX_HEADER: \class{CS 3141: Prof. Kamil's Algorithm Analysis}
#+DATE: \today
#+TITLE: Homework in Org-mode
* 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 AlKhwarizmi}
\date{\today}
\title{Homework in Org-mode}
\hypersetup{
pdfauthor={Musa AlKhwarizmi},
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.

• 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}? Jun 15 '20 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? Jun 15 '20 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]. Jun 15 '20 at 3:55
• I added an example file and the LaTeX output to show the order. Jun 15 '20 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. Jun 15 '20 at 4:00