emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Juan Manuel Macías" <maciaschain@posteo.net>
To: orgmode <emacs-orgmode@gnu.org>
Subject: [patch] ox-latex.el: Add `LATEX_PRE_HEADER' keyword
Date: Sat, 16 Sep 2023 18:00:37 +0000	[thread overview]
Message-ID: <874jjuj8vu.fsf@posteo.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 976 bytes --]

Rationale for this patch: in certain cases, in a LaTeX document, it is
necessary to add code before the class declaration (\documentclass...).
For example, commands like \PassOptionsToPackage, \DocumentMetadata{ },
etc.; or certain packages that should be loaded first using
\RequirePackage{}; and other miscellaneous cases[1]. I think that by
defining a new keyword `latex_pre_header', which behaves the same as
latex_header but concatenated before the class, these situations can be
resolved from Org.

[1] A longer example to export to a pdf that has pdf-x compliance, with
the pdfx package:

\providecommand{\pdfxopts}{x-1a}
\begin{filecontents*}{\jobname.xmpdata}
  \Title{Some Title}
  \Author{Author}
  \Language{es-ES}
  \Keywords{keywords}
  \Publisher{publisher}
\end{filecontents*}
\documentclass{...


-- 
Juan Manuel Macías

https://juanmanuelmacias.com

https://lunotipia.juanmanuelmacias.com

https://gnutas.juanmanuelmacias.com

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-ox-latex.el-latex-Add-LATEX_PRE_HEADER-keyword.patch --]
[-- Type: text/x-patch, Size: 1944 bytes --]

From ac6b743a4489f7bc8ab1cdae7ffd3b36e5f3c1d2 Mon Sep 17 00:00:00 2001
From: Juan Manuel Macias <maciaschain@posteo.net>
Date: Sat, 16 Sep 2023 19:22:39 +0200
Subject: [PATCH] lisp/ox-latex.el (latex): Add `LATEX_PRE_HEADER' keyword

* (org-latex-make-preamble): In some cases it is necessary to add code
before the `\documentclass' line. `LATEX_PRE_HEADER' behaves the same as
`LATEX_HEADER', except that it is concatenated before the class.
---
 lisp/ox-latex.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 14105c7cc..5e97b8b3d 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -124,6 +124,7 @@
     (:latex-class-options "LATEX_CLASS_OPTIONS" nil nil t)
     (:latex-header "LATEX_HEADER" nil nil newline)
     (:latex-header-extra "LATEX_HEADER_EXTRA" nil nil newline)
+    (:latex-pre-header "LATEX_PRE_HEADER" nil nil newline)
     (:description "DESCRIPTION" nil nil parse)
     (:keywords "KEYWORDS" nil nil parse)
     (:subtitle "SUBTITLE" nil nil parse)
@@ -1984,13 +1985,18 @@ specified in `org-latex-default-packages-alist' or
 		       (replace-regexp-in-string
 			"^[ \t]*\\\\documentclass\\(\\(\\[[^]]*\\]\\)?\\)"
 			class-options header t nil 1))))
-	      (user-error "Unknown LaTeX class `%s'" class))))
+	      (user-error "Unknown LaTeX class `%s'" class)))
+         (pre-header (mapconcat
+		      #'org-element-normalize-string
+		      (list (plist-get info :latex-pre-header) ""))))
     (org-latex-guess-polyglossia-language
      (org-latex-guess-babel-language
       (org-latex-guess-inputenc
        (org-element-normalize-string
 	(org-splice-latex-header
-	 class-template
+         (if pre-header
+	     (format "%s\n%s" pre-header class-template)
+	   class-template)
 	 (org-latex--remove-packages org-latex-default-packages-alist info)
 	 (org-latex--remove-packages org-latex-packages-alist info)
 	 snippet?
-- 
2.42.0


             reply	other threads:[~2023-09-16 18:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-16 18:00 Juan Manuel Macías [this message]
2023-09-17 10:02 ` [patch] ox-latex.el: Add `LATEX_PRE_HEADER' keyword Ihor Radchenko
2023-09-17 17:23 ` Timothy
2023-09-18  8:09   ` Ihor Radchenko
2023-09-22 16:38 ` Max Nikulin
2023-09-24 18:42   ` Juan Manuel Macías
2023-09-25 13:58     ` Max Nikulin
2023-09-25 18:49       ` Juan Manuel Macías
2023-09-25 21:57         ` Thomas S. Dye
2023-09-26 15:39           ` Max Nikulin
2023-09-26 19:12             ` Juan Manuel Macías
2023-09-28 10:07               ` Max Nikulin
2023-09-28 12:31                 ` Juan Manuel Macías
2023-09-29  2:38                   ` Max Nikulin
2023-10-01 16:32                   ` Max Nikulin
2023-09-28 15:36                 ` AW
2023-10-01 16:02                   ` Max Nikulin
2023-10-01 17:48                     ` Juan Manuel Macías
2023-10-02 10:42               ` Max Nikulin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874jjuj8vu.fsf@posteo.net \
    --to=maciaschain@posteo.net \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).