@@ -62,7 +62,14 @@ function Div(div)
6262 opt = div .attributes .width
6363 if opt then
6464 local width = tonumber (string.match (opt ,' (%f[%d]%d[,.%d]*%f[%D])%%' ))/ 100
65- options = ' {' .. tostring (width ) .. ' \\ columnwidth}'
65+ options = ' {' .. tostring (width )
66+ if div .attributes [' background-color' ] then
67+ -- fix the width for the \colorbox
68+ options = ' {\\ dimexpr' .. tostring (width )
69+ .. ' \\ columnwidth-4\\ fboxsep\\ relax}'
70+ else
71+ options = ' {' .. tostring (width ) .. ' \\ columnwidth}'
72+ end
6673 end
6774
6875 opt = div .attributes .valign
@@ -72,33 +79,30 @@ function Div(div)
7279 ' \\ begin{minipage}' .. options )}
7380 end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{minipage}' )}
7481
75- -- add support for color TODO: background
82+ -- add support for color
7683 opt = div .attributes .color
7784 if opt then
7885 begin_env = begin_env .. List :new {pandoc .RawBlock (' tex' ,
7986 ' \\ color{' .. opt .. ' }' )}
8087 div .attributes .color = nil -- consume attribute
8188 end
8289
90+ opt = div .attributes [' background-color' ]
91+ if opt then
92+ begin_env = List :new {pandoc .RawBlock (' tex' ,
93+ ' \\ colorbox{' .. opt .. ' }{' )}
94+ .. begin_env
95+ end_env = end_env .. List :new {pandoc .RawBlock (' tex' , ' }' )}
96+ div .attributes [' background-color' ] = nil -- consume attribute
97+ end
98+
8399 returned_list = begin_env .. div .content .. end_env
84100
85101 elseif div .classes :includes (' columns' ) then
86- env = ' columns'
87- -- merge two consecutives RawBlocks (\end... and \begin...)
88- -- to get rid of the unwanted blank line
89- local blocks = div .content
90- local rbtxt = ' '
91-
92- for i = # blocks - 1 , 1 , - 1 do
93- if i > 1 and blocks [i ].tag == ' RawBlock' and blocks [i ].text :match ' end'
94- and blocks [i + 1 ].tag == ' RawBlock' and blocks [i + 1 ].text :match ' begin'
95- then
96- rbtxt = blocks [i ].text .. blocks [i + 1 ].text
97- blocks :remove (i + 1 )
98- blocks [i ].text = rbtxt
99- end
100- end
101- returned_list = blocks
102+ -- it turns-out that asimple Tex \mbox do the job
103+ begin_env = List :new {pandoc .RawBlock (' tex' , ' \\ mbox{' )}
104+ end_env = List :new {pandoc .RawBlock (' tex' , ' }' )}
105+ returned_list = begin_env .. div .content .. end_env
102106
103107 else
104108 -- other environments ex: multicols
0 commit comments