Hi Derek,

the ox-latex.el part can be simplified as

 (not (string-match "\\\\usepackage\\[\\(.*?\\)\\]{babel}" header)))

That will make the regex stop before the ']' and is easier to read (at
least for me-TM),

Best,
/PA
ox-latex.el maintainer


On Thu, 21 May 2026 at 15:30, Derek Chen-Becker <[email protected]>
wrote:

> Confirmed, against d34e34f3e.
>
> The replacement text of "utf8]{inputenc} \\usepackage[french, english"
> makes it appear that the regex patterns used in
> `org-latex-guess-babel-language' aren't sufficiently constrained. Checking
> the regex, it's using "\\[.*\\]", which is why you're only seeing this when
> you have more than one extra header (with only one, there's only one set of
> braces).
>
> I took a look and think I have a fix but I want a second opinion. The
> attached patch fixes the regex by changing the greedy match for the
> language to one that only captures what's between the "[...]". I tried
> using a non-greedy qualifier (".*?") and that didn't work, but I feel like
> I always get tripped up by Elisp regex patterns. If someone has a better
> suggestion for the regex I'm open to changing it.
>
> Owned.
>
> Cheers,
>
> Derek
>
> On Wed, May 20, 2026 at 11:41 AM <[email protected]> wrote:
>
>>
>> With the following Org file
>>
>> ----------------------
>> #
>> * subtree
>> :PROPERTIES:
>> :EXPORT_LATEX_HEADER: \usepackage[utf8]{inputenc}
>> :EXPORT_LATEX_HEADER+: \usepackage[french]{babel}
>>                        :END:
>>
>> bak
>> ----------------------
>>
>> upon subtree export (C-c C-e C-s lp), I get an error, the beginning of the
>> backtrace of which is
>>
>> Debugger entered--Lisp error: (error "Invalid use of ‘\\’ in replacement
>>   text")
>>
>> org-latex-guess-babel-language("\\documentclass[11pt]{article}\n\n\n\\usepackage[utf8]{inputenc}
>>   \\usepackage[french]{babel}\n" (:export-options (subtree) :back-end
>>   #s(org-export-backend :name latex :parent nil :transcoders (... ... ...
>> .
>>
>>
>> This occurs with
>>
>> GNU Emacs 30.2 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.43,
>> cairo version 1.18.2) of 2025-08-18
>>
>> with either
>>
>> - a void .emacs and
>>
>> Org mode version 9.8.4 (9.8.4-2f6959 @
>> /home/cochard/.emacs.d/elpa/org-9.8.2/)
>>
>> - a void .emacs and
>>
>> Org mode version 9.8.2 (9.8.2-2ef390 @
>> /home/cochard/.emacs.d/elpa/org-9.8.2/)
>>
>> - emacs -Q and
>>
>> Org mode version 9.7.11 (release_9.7.11 @ /usr/share/emacs/30.2/lisp/org/)
>>
>> For what it's worth: (1) the problem does not show up for every
>> combination
>> of
>>
>> :EXPORT_LATEX_HEADER:
>> :EXPORT_LATEX_HEADER+:
>>
>> (2) I did not succeed in exhibiting the problem with a single
>>
>> :EXPORT_LATEX_HEADER:
>>
>> --
>> EOST (École et Observatoire des Sciences de la Terre)
>> ITE (Institut Terre & Environnement) | [email protected]
>> 5 rue René Descartes                 | Phone: +33 (0)3 68 85 50 44
>> F-67084 Strasbourg Cedex, France     | bureau 110, ancien bât.
>>
>>
>
> --
> +---------------------------------------------------------------+
> | Derek Chen-Becker                                             |
> | GPG Key available at https://keybase.io/dchenbecker and       |
> | https://pgp.mit.edu/pks/lookup?search=derek%40chen-becker.org |
> | Fngrprnt: EB8A 6480 F0A3 C8EB C1E7  7F42 AFC5 AFEE 96E4 6ACC  |
> +---------------------------------------------------------------+
>
>

-- 
Fragen sind nicht da, um beantwortet zu werden,
Fragen sind da um gestellt zu werden
Georg Kreisler

"Sagen's Paradeiser" (ORF: Als Radiohören gefährlich war) => write BE!
Year 2 of the New Koprocracy

Reply via email to