Skip to content

Commit

Permalink
tweak tables so that informative tables work but trailing hlines don'…
Browse files Browse the repository at this point in the history
…t get lost
  • Loading branch information
chrisfenner committed Feb 8, 2024
1 parent a85148c commit ed490d0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 27 deletions.
2 changes: 0 additions & 2 deletions filter/divide-code-blocks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
function CodeBlock(block)
return {
pandoc.RawInline('latex', [[
\vskip 0.5em
\begin{customcodeblock}
\textbf{\textit{\textcolor{codeblock-header}{\small \BeginDemarcated{Code}}}}
]]),
block,
pandoc.RawInline('latex', [[
Expand Down
20 changes: 2 additions & 18 deletions filter/style-fenced-divs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ div_classes =
{
["informative"] = {
["label"] = "Informative comment",
["background"] = "informative-background",
["header"] = "informative-header",
["foreground"] = "informative-foreground",
},
["note"] = {
["label"] = "Note",
["background"] = "informative-background",
["header"] = "informative-header",
["foreground"] = "informative-foreground",
},
["example"] = {
["label"] = "Example",
["background"] = "informative-background",
["header"] = "informative-header",
["foreground"] = "informative-foreground",
},
}

Expand All @@ -28,19 +19,12 @@ function Div(el)
if(class) then
local class_spec = div_classes[string.lower(class)]
if(class_spec) then
local color_bg = class_spec["background"]
local color_hdr = class_spec["header"]
local color_fg = class_spec["foreground"]
local label = class_spec["label"]

return{
pandoc.RawBlock('latex', '\\vskip 0.5em'),
pandoc.RawBlock('latex', string.format('\\begin{mdframed}[linewidth=0pt,backgroundcolor=%s,skipabove=\\parskip,nobreak=true]', color_bg)),
pandoc.RawBlock('latex', string.format('\\textbf{\\textit{\\textcolor{%s}{\\small\\BeginDemarcated{%s}}}}', color_hdr, label)),
pandoc.RawBlock('latex', string.format('\\color{%s}', color_fg)),
pandoc.RawBlock('latex', string.format('\\BeginInformative{%s}\n', label)),
el,
pandoc.RawBlock('latex', string.format('\\EndDemarcated{%s}', label)),
pandoc.RawBlock('latex', '\\end{mdframed}')
pandoc.RawBlock('latex', string.format('\\EndInformative{%s}', label)),
}
end
end
Expand Down
14 changes: 7 additions & 7 deletions filter/tabularx.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,14 @@ function Table(tbl)
latex_code = latex_code .. '\\hline\n'
end
latex_code = latex_code .. '\\endfoot\n'
end

-- Write out all the footer rows again for the last footer.
latex_code = latex_code .. TabularRows(tbl.foot.rows, true, true, plain, tbl.colspecs)
if not plain then
latex_code = latex_code .. '\\hline\n'
end
latex_code = latex_code .. '\\endlastfoot\n'
-- Write out all the footer rows again for the last footer.
latex_code = latex_code .. TabularRows(tbl.foot.rows, true, false, plain, tbl.colspecs)
if not plain then
latex_code = latex_code .. '\\hline\n'
end
latex_code = latex_code .. '\\endlastfoot\n'

--
-- Body
Expand All @@ -320,7 +320,7 @@ function Table(tbl)
end

if not plain then
latex_code = latex_code .. '\\hline\n'
latex_code = latex_code .. '\\hlineifmdframed\n'
end

--
Expand Down
21 changes: 21 additions & 0 deletions template/tcg.tex
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@
\definecolor{informative-header}{RGB}{75, 77, 78}
\definecolor{informative-foreground}{RGB}{10, 10, 10}


%
% code block style
%
Expand All @@ -282,6 +283,26 @@
backgroundcolor=codeblock-background,
skipabove=\parskip,
nobreak=true]{customcodeblock}
\newmdenv[
linewidth=0pt,
backgroundcolor=informative-background,
skipabove=\parskip,
nobreak=true]{informative}

\newcommand{\hlineifmdframed}{}
\newcommand{\BeginInformative}[1]{
% HACK: We need to add an extra hline to the ends of tables inside of notes, because
% (we don't know why) footers are dropped in tables inside of mdframeds.
\renewcommand{\hlineifmdframed}{\hline}
\begin{informative}
\textbf{\textit{\textcolor{informative-header}{\small \BeginDemarcated{#1}}}}
\color{informative-foreground}
}
\newcommand{\EndInformative}[1]{
\textbf{\textit{\textcolor{informative-header}{\small \EndDemarcated{#1}}}}
\end{informative}
\renewcommand{\hlineifmdframed}{}
}

\usepackage{fontspec}
\setmainfont{Arial}
Expand Down

0 comments on commit ed490d0

Please sign in to comment.