I'm using a workflow based on pandoc
and Latex to produce papers with my companies layout. Part of the formatting are captions set inside the margin and sometimes using images that span text and margin area. Both can easily be achieved with the sidenotes
package. It enables large figures modifying the figure*
environment.
In a plain text document switching between regular figure
and figure*
is of course no problem. But I have to use an automated workflow with pandoc
from markdown through Latex to PDF. Unfortunately, pandoc
offers no built-in option to switch between starred and regular environment. Thus, I've written a Lua filter which wraps figures marked as starred inside a group and in there locally redefines figure
to act like figure*
. This is necessary since pandoc
always outputs regular figure
commands. Unfortunately, I can't get it to work. Here is a MWE with a short Latex example which could be a pandoc
output:
% !TeX lualatex\documentclass{article}\usepackage{sidenotes}\usepackage[outer=4cm]{geometry}\usepackage{blindtext}\begin{document}\blindtext\begingroup\RenewEnvironmentCopy{figure}{figure*}\begin{figure}\rule{\linewidth}{2ex}\sidecaption{some text}\end{figure}\endgroup\end{document}
The log shows the following error message:
! TeX capacity exceeded, sorry [save size=200000].\tl_set:Nn ..._set:Ne #1{\__kernel_exp_not:w {#2}}l.11 \rule {\linewidth}{2ex}If you really absolutely need more capacity,you can ask a wizard to enlarge me.
Enlarging TeX's capacity doesn't solve the problem. The problem also persists if I load graphicx
and use an image instead of a rule.
I'm hoping for some ideas how to solve this.
Other approaches to locally redefine figure
as figure*
are also very welcome. But its obligatory that in the Latex document the environment itself is typed as simple figure
since this output is kind of hardcoded in pandoc
.
Edit
Thanks to @cabohas solution I got it to work. Here is the Lua filter I use with pandoc like pandoc -s -L path/to/filter.lua file.md -o file.tex
:
if FORMAT:match 'latex' then function Figure (elem) local starred = elem.content[1].content[1].attributes['starred'] if starred and starred == "true" then return { pandoc.RawInline('latex', '\\defaultwidefiguretrue'), elem, pandoc.RawInline('latex', '\\defaultwidefigurefalse') } else return elem end endend