emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Patch] Pre-/postpend arbitrary LaTeX code to a section


From: Ihor Radchenko
Subject: Re: [Patch] Pre-/postpend arbitrary LaTeX code to a section
Date: Wed, 21 Sep 2022 16:55:48 +0800

Adding Daniel Fleischer (the ox-latex maintainer) to this exchange.

Juan Manuel Macías <maciaschain@posteo.net> writes:

> Ihor Radchenko writes:
>
>> I do not like this idea.
>> Please remember that headlines may be exported as parts, sections,
>> subsections, list items, or paragraphs depending on the headline level.
>> Arbitrary pre/post commands may unexpectedly break things during export.
>
> I don't see why, if the user knows LaTeX and knows what he/she is doing.
> Sometimes it's just adding an "\addtocontents" just before the
> section/subsection,etc. The property that adds the string before and the
> property that adds the string after are understood to affect the entire
> heading at the current level and its contents, including lower levels.
> For example, if someone wants the current heading (and all its
> sublevels) not to be included in the TOC but to be included in the
> headers of the pages, it would suffice to (I keep here the original name
> of the properties that I proposed in the patch, but I think Maxim's
> proposed name is more accurate):
>
> -----------------------------------
>
> * Section
>   :PROPERTIES:
>   :presec:  \setcounter{secnumdepth}{0}
>   :presec+:  
> \addtocontents{toc}{\protect\setcounter{tocdepth}{0}\ignorespaces}
>   :postsec: \setcounter{secnumdepth}{2}
>   :postsec+: 
> \addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces}
>   :END:
> Lorem ipsum dolor.

There is nothing wrong about this, but I feel that this kind of approach
is encouraging to shoot your own leg a bit too much. It will be better
if Org provides a semantics that is facilitating more safe approach.
More below.

> Which would pass to LaTeX as:
>
> \setcounter{secnumdepth}{0} 
> \addtocontents{toc}{\protect\setcounter{tocdepth}{0}\ignorespaces}
>
> \section{Section}
> Lorem ipsum dolor.
> \subsection{Subsection one}
> lorem
> \subsection{Subsection two}
> ipsum
>
> \setcounter{secnumdepth}{2} 
> \addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces}
> ----------------------------------
>
> (The above can even be simplified from LaTeX by defining a simple
> environment, but I've exemplified it like this to make it look better).
>
> In what situations might this return unexpected results?

It may produce unexpected results if "Section" heading is demoted all
the way to paragraph. Also, :presec/:postsec property names are
confusing --- it is unclear if they are specific to LaTeX. (when about,
say, Beamer)

>> However, I do agree that per-heading control over latex export is
>> currently cumbersome.
>>
>> The canonical ox-latex approach to customize headline export is
>> org-latex-classes variable. This variable defines (among other things)
>> pre/post commands during headline export:
>
> Apologies in advance if I misunderstood what you're suggesting, but
> isn't the "org-latex-classes" property supposed to affect the structure
> of the entire document? What I'm proposing here is rather something
> specific to particular headings (and its entire content), like the
> ":ALT_TITLE:" property. If I understand correctly, what you are
> suggesting is that org-latex-classes can have "local values" for
> specific headings, if such headings are 'marked' with some property?

Yes, org-latex-classes is controlling the entire document. What I am
proposing (as an alternative) is subtree-level equivalent of
org-latex-classes that is also close to org-latex-classes semantics.

More concretely, I mean something like

* Section
  :PROPERTIES:
  :attr_latex: :prepend "section" \setcounter{secnumdepth}{0}
  :attr_latex+: :prepend "section" 
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}\ignorespaces}
  :attr_latex+: :append "section" \setcounter{secnumdepth}{2}
  :attr_latex+: :append "section" 
\addtocontents{toc}{\protect\setcounter{tocdepth}{2}\ignorespaces}
  :END:

I suggest to use more canonical attr_latex that explicitly limits the
export backend.

Further, it mentions a regexp limiting the applicable LaTeX environment
("section"). In other environments, the code will be omitted.

-- 
Ihor Radchenko,
Org mode contributor,
Learn more about Org mode at https://orgmode.org/.
Support Org development at https://liberapay.com/org-mode,
or support my work at https://liberapay.com/yantar92



reply via email to

[Prev in Thread] Current Thread [Next in Thread]