You had the right idea with creating your own LaTeX class. The problem is how templates are filled with org-fill-template
by default. I'm not so great with Lisp, but this hack will do the trick. Add the following to the .emacs file:
(defun my-section (level text) (let* ((in "") (out "") (short-title (if (string-match "\\[.*\\]" text) (substring text (match-beginning 0) (match-end 0)) nil))) (if short-title (setq text (substring text (match-end 0) -1))) (setq in (org-fill-template "\\section%S{%s}" (list (cons "S" (or short-title "")) (cons "s" (or text "")))) out (copy-sequence "\\end{section}")) (cons text (list in out in out)))) (add-to-list 'org-export-latex-classes '("test" "\\documentclass{article}" my-section))
This declares a new latex class, adding the class to org-export-latex-classes
. Here we declare, instead of the usual element \\section{%s}
function that takes two parameters --- the current level and the header text --- and returns the changed cons cell. Some information on this information can be found in org-latex-export.el.
Above adding to the list, we actually define a function. This is, frankly, a hacked version, and I did a lot from the org-beamer-sectioning
function in the org-beamer-sectioning
file. This function basically looks for a title for everything that looks like a short LaTeX label (ie [....]
) removes it from the title and attaches it to the actual section label. Right now, this hack will only generate \section
expressions, no matter how deep the level is - if you want something more intelligent, like \chapter
or \subsection
or even unnumbered elements, you will need to do a few more Lisping; again, contact org-beamer.el for help.
This bit is org-mode
code
#+latex_class: test * [short 1] this is 1 star test ** this is a 2 star test *** [short 3] this is a 3 star test **** what happens
exports to LaTeX as (only relevant sections shown here):
\section[short 1]{ this is 1 star} \label{sec-1} test \section{ this is a 2 star } \label{sec-1-1} test \section[short 3]{ this is a 3 star} \label{sec-1-1-1} test \section{ what happens } \label{sec-1-1-1-1} \end{section} \end{section} \end{section} \end{section}
Although this is not a direct org-mode
solution, it seems to work and may be the starting point for you. The other day, I could try to write it correctly and put it into the org-mode
distribution.