Pedro Andres Aranda Gutierrez <[email protected]> writes:

>> Now, we are copying the logic from ox-latex. If we ever change how
>> ox-latex handles things, and forget this place, it will be a bug we
>> could have avoided.
>
> I don't get this.
> 1. We don't want to have this ox-latex related code in ox-latex, OK
> 2. I'm generating foundational Beamer (and LaTeX) code here. Nothing exotic
> that will change in the way LaTeX expects files.

You have

    +;; Generate the preamble up to the theme
    +(defun org-beamer-class-template(info)
    +  "Generate the class template from INFO.
    +This will include class-pre, class and theme definitions."
    +  (let* ((class-pre (plist-get info :latex-class-pre))
    +         (class-options (concat "[" (plist-get info :latex-class-options) 
"]")))
    +    ;; See org-latex--mk-options:
    +    ;; Accept class options with and without square brackets
    +    (setq class-options (replace-regexp-in-string "\\`\\[+" "[" 
class-options))
    +    (setq class-options (replace-regexp-in-string "\\]+\\'" "]" 
class-options))
    +    (concat class-pre (and class-pre "\n")
    +            "\\documentclass" class-options "{beamer}\n"
    +            (org-beamer-theme-settings info))))

This is basically copying what

              +(defun org-latex--make-class-template (info snippet?)

does.

Now, imagine that we want to change org-latex--make-class-template in
the future. For example, to add a new feature.
We will always have to remember changing org-beamer-class-template as
well. Otherwise, ox-beamer will not be able to support the more general
ox-latex feature.

Let's me give you a more concrete example of a problem where your
implementation will lose even existing ox-latex features.

ox-beamer currently has

(unless (assoc "beamer" org-latex-classes)
  (add-to-list 'org-latex-classes
               '("beamer"
                 "\\documentclass[presentation]{beamer}"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))

So, users are able to customize the template directly changing "beamer"
entry in org-latex-classes, if deemed necessary.

With your code, all that customization will be ignored.

Your code can indeed be fixed to account for such possibility, but that
will likely require the dumb approach I suggested with splicing into
user-provided template.

>> What about very dumb approach - call `org-latex-make-preamble', find
>> \documentclass... inside, and then insert the theme definition right
>> after \documentclass, in the already-expanded preamble?
>>
> IMHO, that, exactly that, is what makes the code so hard to understand.

What I propose is somewhat similar to what `org-splice-latex-header' does.
The current approach we have there is indeed clunky. FYI, Timothy has
been working on ultimate solution to this - so-called conditional
preamble, where the templates are much more flexible. But alas, we do
not have that yet.

> Give the patches a chance...

I do not mind the general idea of the patches, but I want to make sure
that implementation will not backfire in the future.

-- 
Ihor Radchenko // yantar92,
Org mode maintainer,
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