What’s the best way to let org-mode in Emacs add a strike-through on every heading with a “DONE” keyword when I export my document to LaTeX? Right now my settings are
(defun my-latex-filter-headline-done (text backend info)
"Ensure dots in headlines."
(when (org-export-derived-backend-p backend 'latex)
(save-match-data
(when (let ((case-fold-search t))
(string-match "\\\\\\([a-z]+\\){\\(.*DONE.*\\)}"
text))
(if (not (string-match ".*hsout.*" text))
(replace-match "\\\\\\1{\\\\hsout{\\2}}"
t nil text))))))
(eval-after-load 'ox
'(progn
(add-to-list 'org-export-filter-headline-functions
'my-latex-filter-headline-done)))
And in my document I have
#+LATEX_HEADER: \DeclareRobustCommand{\hsout}[1]{\texorpdfstring{\sout{#1}}{#1}}
So that if I have an org document like
* DONE test
It will export to something like
% header stuff…
\begin{document}
\section{\hsout{{\bfseries\sffamily DONE} test}}
\end{document}
while normally without the strike-through it’s like
% header stuff…
\begin{document}
\section{{\bfseries\sffamily DONE} test}
\end{document}
I have to use the \hsout
macro to make strike-through work in headings. This approach has several faults:
- It depends on the way org-mode generates the LaTeX code. If org-mode changes the way it does that, this approach may break.
- I have to add the
LATEX_HEADER
in all my documents. - Some headings have a short form (
\section[aaaa]{bbbbbbb}
). If I want to include that, I have to add another ugly regexp to my elisp, which is already quite ugly.
Hence my question at the beginning. Anyone knows a better way?
\begin{document}
. – lawlistox-latex.el
has a specific template that is hard-coded. If you like the way thatox-latex.el
converts org headings into a\section
definition (e.g., at line 190 as part oforg-latex-classes
), then you are probably limited to the type of formatting that is permitted within a definition of that nature. Other than modifying the source, another option would be to have a cleanup-function that runs afterox-latex.el
finishes compiling -- e.g., replace-regexp . . .. – lawlist