I have an org-mode document, say
#+TITLE: My Title
* Section
My first section
and I want to export it to LaTeX with org-latex-export-to-latex
.
This generates a .tex
file that I can now compile.
Question: Is there a way to append something like
%%% Local Variables:
%%% coding: utf-8
%%% mode: latex
%%% TeX-engine: xetex
%%% End:
To the end of the .tex
file, so that when I compile it with AUCTex, it will know to use the XeTeX engine to compile it instead of using the default one I have set?
I tried the following
Using the org-export-before-parsing-functions
hook
I defined the functions
(defun insert-at-end (text)
"Insert the specified TEXT at the end of the current buffer."
(save-excursion
(goto-char (point-max))
(insert text)))
(defun add-postamble ()
(insert-at-end "%%% Local Variables: \n")
(insert-at-end "%%% coding: utf-8\n")
(insert-at-end "%%% mode: latex\n")
(insert-at-end "%%% TeX-engine: xetex\n")
(insert-at-end "%%% End: \n"))
Then tried adding it to the org-export-before-parsing-functions
hook via
(add-hook 'org-export-before-parsing-functions
'add-postamble)
What I got was the LaTeX file where the last few lines of the file looked like:
\%\%\% Local Variables:
\%\%\% coding: utf-8
\%\%\% mode: latex
\%\%\% \TeX{}-engine: xetex
\%\%\% End:
\end{document}
Using org-export-filter-final-output-functions
Defined a function
(defun my/org-export-add-lines (output backend info)
"Add custom lines to the exported output."
(when (and (eq backend 'latex)
(string= "add-lines-to-export" (plist-get info :post-export-output)))
(concat output
"%%% Local Variables: \n"
"%%% coding: utf-8\n"
"%%% mode: latex\n"
"%%% TeX-engine: xetex\n"
"%%% End: \n")))
and added them to org-export-filter-final-output-functions
via
(add-to-list 'org-export-filter-final-output-functions 'my/org-export-add-lines)
This did nothing to the final output of the LaTeX file
Augmenting org-latex-classes
Suggested by ChatGPT I also tried to supplement org-latex-classes
with a custom class with a line
("\\end{document}" . "\\end{document}\n%%%% Local Variables:\n%%%% coding: utf-8\n%%%% mode: latex\n%%%% TeX-engine: xetex\n%%%% End:"))
but that didn't work.
"Local variables"
I also tried adding "local-variables"?
# Local Variables:
# org-coding: utf-8
# org-mode: latex
# org-TeX-engine: xetex
# End:
to my org buffer according to Using File Local Variables in org-mode, but this didn't seem to do anything. Perhaps I misunderstood what they were saying?
final-output
filter, when/why/how do you expect the condition(string= "add-lines-to-export" (plist-get info :post-export-output))
to be true?