pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

`linestretch` does not take effect for latex beamer slides

Open jdgx opened this issue 1 year ago • 3 comments

Issue

Compile the following with pandoc -o output.pdf -V linestretch=2 -t beamer (tested with pandoc 3.1.2):

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.

and observe that the space between the lines is not enlarged (compared to linestretch=1 or without linestretch variable).

Positive counter example: when compiling to regular pdf document (via latex), without the -t beamer option, the line spacing is set according to the linestretch variable as expected.

Root cause

I think, I've also identified the root cause in the default.latex template:

  • If beamer is used, the ignorenonframetext option is handed over to the class options. This has the effect that text outside of a frame is ignored.

  • The template includes the \setstretch command only after \begin{document}, but not inside any frame.

Possible solutions

  • Option 1: Adapt the template to include \setstretch in the preamble, for example, right before \begin{document}. This fixes the issues. This approach also fits to the package documentation of the setspace package. There it is mentioned that \setstretch can be used in the preamble of the document; though it is not explicitly forbidden to use it outside of the preamble.

  • Option 2: Removing the ignorenonframetext option would also fix the issues. Since the option is (exclusively?) required for the beamerarticle layout, it might make sense to put the option in the template behind an $if(beamerarticle)$ guard.

Personally, I tend to go for Option 1. Option 2 could be implemented in addition, but I cannot really judge if this makes sense. I'm not that familiar with beamer and beamerarticle and cannot assess possible side effects.

Any opinions on this? I'm happy to create a pull request for Option 1 and/or Option 2 if desired.

jdgx avatar Jul 29 '24 12:07 jdgx

I assume that if we added \setstretch after \begin{document}, there was a reason for it. Perhaps something has chaged? Can you test it to make sure it works in the preamble?

jgm avatar Jul 29 '24 17:07 jgm

My minimal example, and also some of my private real world examples work like charm with \setstretch in the preamble.

However, digging through the search result for setstrech/linestretch in the issues revealed the history behind it. Let me try to summarize:

  • The move from preamble to the body happend with #5378 The reason was to have the comand after \maketitle and \tableofcontents.

  • In #5371 an alternative approach was discussed (leave \setstretch in the preamble, but protect title, toc, lof, bibliography etc. with explicit singlespace environments). This approach was discarded in favor of #5378. Mind John's comment:

    If the fix in 5378 turns out to be a bad idea, we can revisit.

    The time to revisit might me now :-)

  • Then there were issues with Korean language (#5179, #, which where solved by the move. But solving these issues was probably more like a side effect/work around. Right now, I didn't have the time to check if these issues are still there with \setstretch back in the preamble.

  • When merging the latex and beamer template (#3879) it was questioned if linestretch should be ignored for beamer overall:

    Should more conditionals be added to prevent variables not applicable to Beamer from being passed on (linestretch, geometry, lof, lot)?

    I didn't see an explicit reply in the discussion, but obviously \setstretch didn't end up behind a $if(beamer)$ guard - which is think was the right decision, because in my opinion the linestretch option also makes sense for beamer.

  • In #2585 a user issued that \setstretch didn't work in the table of contents. No further details were given.

  • #1376 discusses linestretch in respect to the bibliography.

Regardless of the technical implementation, I would say

  • linestretch should be usable with beamer
  • linestretch should not affect the title
  • Concerning table of contents, bibliography and list of figures etc., I'm not quite sure. Personally I like a bit more spacing in table of contents etc., but I'm not sure if this is a good default behavior.

jdgx avatar Jul 30 '24 07:07 jdgx

Thanks for doing all that research, it really helps.

Well, I suppose one obvious approach would be to move setstretch to the preamble and protect \maketitle in a singlespace environment. I agree, personally, that the linestretch should affect the TOC.

In any case the issue with Korean should be tested.

jgm avatar Jul 30 '24 15:07 jgm