Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
somelinguist opened this issue Dec 12, 2023 · 5 comments

Comments

@somelinguist
Copy link

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
Copy link
Author

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

pandoc-ling/pandoc-ling.lua

Lines 210 to 222 in a9eae71

-- add temporary divs to first header level
-------------------------------------------
-- will be removed again once the chapters are counted
function addDivToHeader (head)
if head.tag == "Header"
and head.level == 1
and head.classes[1] ~= "unnumbered"
then
head.attr = {id = head.identifier, class = "restart"}
return pandoc.Div(head)
end
end

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:

pandoc-ling/pandoc-ling.lua

Lines 228 to 238 in a9eae71

function processDiv (div)
-- keep track of chapters (header == 1)
-- included in this loop by trick "addDivToHeader"
if div.content[1].tag == "Header" and div.content[1].classes[1] == "restart" then
chapter = chapter + 1
counterInChapter = 0
div.content[1].attr = {id = div.content[1].identifier, class = ""}
-- remove div
return div.content
end

somelinguist added a commit to somelinguist/pandoc-ling that referenced this issue Dec 12, 2023
add "restart" class instead of overwriting other classes
only remove inserted "restart" class
@somelinguist
Copy link
Author

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
Copy link
Author

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

@somelinguist
Copy link
Author

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 added a commit to somelinguist/pandoc-ling that referenced this issue Dec 13, 2023
use List.insert to add "restart" class to header
added back check that "restart" class had been added
@somelinguist
Copy link
Author

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 (somelinguist@4e4da4e) 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant