@@ -26,18 +26,28 @@ Note: You need to include multicol latex package to get balanced columns
2626local List = require ' pandoc.List'
2727
2828function Div (div )
29- options = ' '
30- local env = div . classes [ 1 ]
29+ local options = ' '
30+ local env = ' '
3131 local returned_list
3232 local begin_env
3333 local end_env
3434 local opt
3535
3636 -- if the div has no class, the object is left unchanged
37- if not env then return nil end
37+ -- if the div has no class but an id, div.classes ~= nil
38+ -- TODO: use a div with no class to build a 'scope' in Latex
39+ -- usefull for user who would throw inline Latex code and limit it's
40+ -- effect.
41+ if not div .classes or # div .classes == 0 then return nil end
3842
3943 -- if the output is beamer do columns
4044 if FORMAT :match ' beamer' then
45+ -- only arbitrary environment support in beamer for now. Environment has to
46+ -- be the firs class name.
47+ env = div .classes [1 ]
48+ if options == ' ' and div .attributes [' data-latex' ] then
49+ options = div .attributes [' data-latex' ]
50+ end
4151 -- build the returned list of blocks
4252 begin_env = List :new {pandoc .RawBlock (' tex' ,
4353 ' \\ begin' .. ' {' .. env .. ' }' .. options )}
@@ -47,8 +57,8 @@ function Div(div)
4757 -- if the format is latex then do minipage and others (like multicol)
4858 elseif FORMAT :match ' latex' then
4959 -- build the returned list of blocks
50- if env == ' column' then
51- -- opt = div.attributes['width']
60+ if div . classes : includes ( ' column' ) then
61+ env = ' column '
5262 opt = div .attributes .width
5363 if opt then
5464 local width = tonumber (string.match (opt ,' (%f[%d]%d[,.%d]*%f[%D])%%' ))/ 100
@@ -63,7 +73,8 @@ function Div(div)
6373 end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{' .. ' minipage' .. ' }' )}
6474 returned_list = begin_env .. div .content .. end_env
6575
66- elseif env == ' columns' then
76+ elseif div .classes :includes (' columns' ) then
77+ env = ' columns'
6778 -- merge two consecutives RawBlocks (\end... and \begin...)
6879 -- to get rid of the unwanted blank line
6980 local blocks = div .content
@@ -82,13 +93,20 @@ function Div(div)
8293
8394 else
8495 -- other environments ex: multicols
85-
86- -- process supported options
87- opt = div .attributes [' column-count' ] -- this synthax needed due to '_'
88- if opt then options = ' {' .. opt .. ' }' end
89-
90- -- default if no known options
91- if options == ' ' then options = div .attributes .data - latex end
96+ if div .classes :includes (' multicols' ) then
97+ env = ' multicols'
98+ -- process supported options
99+ opt = div .attributes [' column-count' ]
100+ if opt then options = ' {' .. opt .. ' }' end
101+ else
102+ -- Latex skilled users can use arbitrary environments passed as
103+ -- the first (and only signifiant) class name.
104+ env = div .classes [1 ]
105+ -- default if no known options
106+ if options == ' ' and div .attributes [' data-latex' ] then
107+ options = div .attributes [' data-latex' ]
108+ end
109+ end
92110
93111 begin_env = List :new {pandoc .RawBlock (' tex' ,
94112 ' \\ begin' .. ' {' .. env .. ' }' .. options )}
@@ -105,9 +123,11 @@ function Div(div)
105123 div .attributes .style = div .attributes .style ..
106124 ' ; column-count: ' .. opt
107125 else
108- div .attributes .style = ' column-count:' .. opt
126+ div .attributes .style = ' column-count: ' .. opt
109127 end
110128 div .attributes [' column-count' ] = nil
129+ -- column-count is "consumed" by the filter otherwise it would appear as
130+ -- data-column-count="…" in the resulting document
111131 returned_list = List :new {pandoc .Div (div .content , div .attr )}
112132 end
113133 end
0 commit comments