cysouw / pandoc-ling

Pandoc Lua filter for linguistic examples
Creative Commons Zero v1.0 Universal
36 stars 6 forks source link

Beamer frame attributes not always output when using pandoc-ling filter #15

Open somelinguist opened 9 months ago

somelinguist commented 9 months ago

Hello,

Thanks for this wonderful filter.

I was trying to create a slide show with Beamer using the pandoc-ling filter. However, I discovered that when using the filter, Beamer frame attributes don't always get passed through.

For example, given the following input:

---
title: In the morning
---

# In the morning {.t}
- Test list
- Test list

# Getting up {.t}

- Turn off alarm
- Get out of bed

If I run pandoc without the filter, for example pandoc -t beamer beamer-ling.md --pdf-engine=xelatex -o beamer.tex, I get the following tex output. Note the [t] option passed to the frame environments:

\begin{frame}[t]{In the morning}
\phantomsection\label{in-the-morning}
\begin{itemize}
\tightlist
\item
  Test list
\item
  Test list
\end{itemize}
\end{frame}

\begin{frame}[t]{Getting up}
\phantomsection\label{getting-up}
\begin{itemize}
\tightlist
\item
  Turn off alarm
\item
  Get out of bed
\end{itemize}
\end{frame}

However, when running pandoc with the filter (pandoc -t beamer beamer-ling.md --pdf-engine=xelatex --lua-filter ./pandoc-ling.lua -o beamer-ling.tex), even when not including and kinds of numbered/glossed examples, the [t] option is not included in the tex output for the frames:

\begin{frame}{In the morning}
\phantomsection\label{in-the-morning}
\begin{itemize}
\tightlist
\item
  Test list
\item
  Test list
\end{itemize}
\end{frame}

\begin{frame}{Getting up}
\phantomsection\label{getting-up}
\begin{itemize}
\tightlist
\item
  Turn off alarm
\item
  Get out of bed
\end{itemize}
\end{frame}

Any ideas?

Thanks again for this great filter!

somelinguist commented 9 months ago

It looks like maybe the frame attribute classes are getting removed from first level headings at line 219:

https://github.com/cysouw/pandoc-ling/blob/a9eae71593c0d12e3db68342d0c7e22ec2b23deb/pandoc-ling.lua#L210-L222

I don't know enough about Lua to suggest a fix, but I think any solution would probably need to take into account lines 230-238 as well:

https://github.com/cysouw/pandoc-ling/blob/a9eae71593c0d12e3db68342d0c7e22ec2b23deb/pandoc-ling.lua#L228-L238

somelinguist commented 9 months ago

The change in my fork seems to work? Again, I don't know much Lua, but the changes I made:

  1. Add a "restart" class to the header instead of overwriting existing ones
  2. Only remove the inserted "restart" class when it's done instead of existing classes.

The removal code is based on the example for minted here:

https://github.com/pandoc/lua-filters/blob/2aa98bfda556c7d4dfb8e30c20b318b6fd1f5091/minted/minted.lua#L237-L248

Running on the modified filter on my example maintains the beamer frame attributes, and I tried it with a few examples from the readme here that didn't seem to break anything. But, again, I don't know much about Lua. :)

somelinguist commented 9 months ago

I just realized I probably broke the intent of tracking the headers by accidental removing the check for "restart". :)

somelinguist commented 9 months ago

I did some further tests, and I guess I didn't actually seem to break it. But something doesn't seem quite right about skipping the check.

somelinguist commented 9 months ago

Ok. I figured out the reason it still worked was because only the first level headers were being converted to divs.

The second commit in my fork (https://github.com/somelinguist/pandoc-ling/commit/4e4da4eeccdc5ce5b63814057397ab2308b730a6) adds back the check and is probably more efficient than my first attempt. It just inserts the "restart" class at index 1 so that it's easy to check later and remove.