Pandoc: LaTex/Beamer add hook before \begin{frame}... and after \end{frame}

Created on 25 Feb 2018  路  9Comments  路  Source: jgm/pandoc

I think it would be a great idea to add the possibility to call a hook macro in latex/beamer right before and after the creation of a frame.

This would make it possible to translate something like

## Exercise: a new quiz {hook=exercisemode}

Just an  example ...

## No exercise 

Nothing else

to an latex output with might change the behavior frame title styling etc:

\exercisemodetrue
\begin{frame}
\frametitle{%
\protect\hypertarget{exercise-a-new-quiz}{%
 Exercise: a new quiz }}

Just an example ...
\end{frame}
\exercisemodefalse

\begin{frame}
\frametitle{%
\protect\hypertarget{o-exercise}{%
 No exercise  }}

Nothing else ...
\end{frame}

I need something like this desperately to change the frame title style of a slide when it shows exercises..

Thanks
Norman

LaTeX writer

All 9 comments

Do you really need to enclose the complete frame in the exercise mode, i.e. do you need \exercisemodetrue to appear before \begin{frame} and \exercisemodefalse to appear after \end{frame}?

If it would suffice to wrap just the content of your frame into the exercise mode, you could use a simple lua-filter like

local exercise = false

function Header(h)
    local exercisemode = pandoc.Null()

    -- handle end of previous excercise mode
    if exercise then
        exercise = false
        exercisemode = pandoc.RawBlock("latex", "\\exercisemodefalse")
    end

    -- handle current header: start exercise if attribut `hook` is set to `exercisemode`
    if h.attributes["hook"] == "exercisemode" then
        exercise = true
        return { exercisemode, h, pandoc.RawBlock("latex", "\\exercisemodetrue") }
    end

    -- else return header
    return { exercisemode, h }
end

This filter would produce the following TeX from your example (using --slide-level=2):

\begin{frame}{%
\protect\hypertarget{exercise-a-new-quiz}{%
Exercise: a new quiz}}

\exercisemodetrue

Just an example \ldots{}

\exercisemodefalse

\end{frame}

\begin{frame}{%
\protect\hypertarget{no-exercise}{%
No exercise}}

Nothing else

\end{frame}

If it would suffice to wrap just the content of your frame into the exercise mode

then you could also you write the raw TeX (i.e. \exercisemodetrue) as part of the markdown

If you write raw TeX like @mb21 suggested, this raw TeX would be part of the frame before. Because every Header of a certain level is acting greedy until the next Header of the same or higher level. So the raw TeX-Block in the AST would be part of the last Header, which means that it will be written inside of the frame before the current frame. And that is not a solution, because you need it between \end{frame} and \begin{frame}.

So that is not the right way to fix the problem.

(Yes, I do think this is a design problem of the current AST-design! ;-) )

That is also true for (any) filter suggestion, because setting anything inside of a frame won't change the current frame (and also not the next frame!) or anything inside of the frame title environment. If you write \begin{frame} everything inside will be like in a sandbox and don't harm the frame code.

So, change the behavior inside of the pandoc latex-writer is, for me, the only possible solution. -- Sorry.

Thanks to @mb21 and @cagix, but it your ideas won't work .. :-(

Currently we reorganize the AST for slides in the writer,
so the filter can't get to the slide structure.

Now that we have native Divs, we could consider reorganizing
things:

  • the beamer, reveal.js, etc. writers would expect things to
    be already organized into a serious of Divs with class
    "slide", corresponding to the slides.

  • we'd have a built-in filter that creates this Div
    structure from the regular AST in the same way as
    currently

  • the writer would check to see if the AST includes the
    Div structure for slides, and call this filter if not

  • but the filter could also be called manually from e.g.
    a lua filter; this would allow people to do fine-grained
    adjustments on slide structure from within a lua filter.

  • writers could also just include the Div structure for
    slides manually.

It's a bit complex but worth considering.

I'm not sure about if this would make it easier. Complex, may be to complicated, if you would ask me.
If I understand it correctly

something like

# section
## slide
Lore ipsum ...

## slide
Lore ipsum ...

will first be converted to something like

[Div class="section" content="section",
  [Div class="slide" content="Lore Ipsum ..."],
  [Div class="slide" content="Lore ipsum ..."]
]

so that it will be possible to add something in between like

[Div class="section" content="section",
  [RawBlock ...],
  [Div class="slide" content="Lore Ipsum ..."],
  [Div class="slide" content="Lore ipsum ..."],
  [RawBlock ...]
]

or do I misunderstood something?

Yes, you understand the idea.

Okay, that would be perfect. - When it will arrive in the releases? ;-) --- Yes, i'm pushing, 'cause I need it badly! :-)

Sorry,

is there anything I could test or use in this direction? -- Maybe in a branch? ;-)

Yours
Norman

Sorry...I have limited time to work on pandoc; you shouldn't expect any
changes soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

johnridesabike picture johnridesabike  路  4Comments

velimir picture velimir  路  4Comments

krobelus picture krobelus  路  4Comments

tolot27 picture tolot27  路  5Comments

chrissound picture chrissound  路  4Comments