Org-mode & Latex export: Any way to specify short and long names in partitioning commands? Workarounds?

In standard latex, you can use something like ...

\section[short head]{A longer and more meaningful heading version for the section} 

... which gives both a long and a short version of a section (or another partitioning command). Thus, taking into account both significant sectional โ€œheadersโ€ and reasonably looking moving heads, TOC, ray navigation, etc.

Is there a way to easily achieve this in org mode? (That is, without hard coding the partitioning commands in LATEX fragments and, thus, overcoming most of the flexibility of changing partitioning levels and repurposing content for diagram classes, books, and articles, what is the reason for my desire to try orgmode in the first place?)

I tried a "workaround" that didn't work. I tried changing the possible latex export classes by adding another class to org-export-latex-classes . This new class changes partitioning commands from \section{%s} to \section%s (EDIT-Fixed typo in slashes). Then I tested with [short]{longer version} in the orgmode sections of the file. It worked, except that it acted as if the title of the longer version was just "{" and the "longer version" was text text! What is the reason for this?

+6
source share
3 answers

Starting with version 8.0, the strategy "org-export-latex-classes" will no longer work.

Instead, and I dare say much more elegantly, you can set the ALT_TITLE property for the title.
See http://orgmode.org/manual/Table-of-contents.html .

The following org code:

 * The Long Title of Section 1 :PROPERTIES: :ALT_TITLE: Section 1 :END: Lorem ipsum. ** The Long Title of Subsection 1-1 :PROPERTIES: :ALT_TITLE: Subsection 1-1 :END: Dolor sit amet. 

will be exported to LaTeX as:

 [...] \section[Section 1]{The Long Title of Section 1} \label{sec-1} Lorem ipsum. \subsection[Subsection 1-1]{The Long Title of Subsection 1-1} \label{sec-1-1} Dolor sit amet. 
+4
source

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.

+1
source

In latex, you can use the following commands to determine the text that should appear in the title to replace section names. But TOC will still contain the original names.

 \chaptermarks \sectionmarks \subsectionmarks ... 

So in org-mode you can write

 * Long section title #+LaTeX: \sectionmark{Short title} 

edit: it actually does not work on the very page where the section name is displayed. In this, only the full name is still placed in the header.

0
source

Source: https://habr.com/ru/post/909415/


All Articles