# How to define LaTeX document class for org-mode export (other than default)?

I want to add to org-latex-classes new class, namely "exam" (as described here: https://www.sharelatex.com/templates/exams/exam), here's a preview of an example document beginning:

\documentclass[12pt]{exam}
\usepackage[utf8]{inputenc}

\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb}
\usepackage{multicol}

\newcommand{\class}{Math I}
\newcommand{\term}{Winter 2014}
\newcommand{\examnum}{Exam 1}
\newcommand{\examdate}{1/1/2014}
\newcommand{\timelimit}{60 Minutes}

\runningheader{\class}{\examnum\ - Page \thepage\ of \numpages}{\examdate}

\begin{document}

\noindent
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}} r   @{\extracolsep{6pt}} l}
\textbf{\class} & \textbf{Name:} & \makebox[2in]{\hrulefill}\\
\textbf{\term} &&\\
\textbf{\examnum} &&\\
\textbf{\examdate} &&\\
\textbf{Time Limit: \timelimit} & Teaching Assistant & \makebox[2in]{\hrulefill}
\end{tabular*}\\
\rule[2ex]{\textwidth}{2pt}

[...]

\begin{questions}

\question[1] Calculate 2+2.

[...]


I've read answer to this question and documentation for org-latex-classes variable, but I don't understand how to apply given syntax to my case (there are no sections or subsections in "exam", etc.).

I would like to be able to write my exams in org mode where for example new headlines would be different questions, number of points would be handled by property drawers, #+TITLE would be \examnum or \class and #+DATE would be \examdate, etc.

Is it possible? If yes - is there a documentation which shows how to translate org-mode markup into particular LaTeX document markup with more detail than org-latex-classes doc?

It is kind of possible but would normally require many little tweaks, since the exam-class is a bit outside more common classes. Here are some pointers to how it could be done.

For customizing title things, there is org-latex-title-command which you could define to be the whole header table and fill in title, and date etc. with elements %t, %d, etc. (see docstring).

Getting headlines as questions is a trickier problem. The easiest part would perhaps be to define an entry in org-latex-classes like:

("exam" "\\documentclass[11pt]{exam}[MORE_PREAMBLE_STUFF]"
("\\question[%s]" . "\\question[%s]")
...
)


And only have the points as the headline for the heading. I understand that this would be unsatisfactory. You could also define a custom function for headline formatting (set org-latex-format-headline-function to this function) but this would again only accept certain arguments and can’t read additional headline properties as I understand it.

But, with a a class entry like the one defined above, you could use

(defun org-latex-format-headline-function-exam
(_todo _todo-type _priority _text tags _info)
(or (car tags) "")


as headline function and let the first tag ((car tags)) be the point for the question.

• Thank you. I will have to try your solution (meanwhile I've been using some yasnippets but it doesn't solve my problem). As a matter of a fact I don't need the points counter in my exams, so I guess the main thing to deal with would be the translation of headlines to questions and lists to {parts} environment. Other thing would be \fillwithdottedlines command which I use a lot (I use rather open questions than test for my exams). Thanks again. – caseneuve Mar 22 '18 at 16:54