@@ -62,7 +62,14 @@ function Div(div)
62
62
opt = div .attributes .width
63
63
if opt then
64
64
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
66
73
end
67
74
68
75
opt = div .attributes .valign
@@ -72,33 +79,30 @@ function Div(div)
72
79
' \\ begin{minipage}' .. options )}
73
80
end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{minipage}' )}
74
81
75
- -- add support for color TODO: background
82
+ -- add support for color
76
83
opt = div .attributes .color
77
84
if opt then
78
85
begin_env = begin_env .. List :new {pandoc .RawBlock (' tex' ,
79
86
' \\ color{' .. opt .. ' }' )}
80
87
div .attributes .color = nil -- consume attribute
81
88
end
82
89
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
+
83
99
returned_list = begin_env .. div .content .. end_env
84
100
85
101
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
102
106
103
107
else
104
108
-- other environments ex: multicols
0 commit comments