From ed490d0c712bed3933889bf2ac4f5512bcdb680f Mon Sep 17 00:00:00 2001 From: Chris Fenner Date: Wed, 7 Feb 2024 18:37:30 -0800 Subject: [PATCH] tweak tables so that informative tables work but trailing hlines don't get lost --- filter/divide-code-blocks.lua | 2 -- filter/style-fenced-divs.lua | 20 ++------------------ filter/tabularx.lua | 14 +++++++------- template/tcg.tex | 21 +++++++++++++++++++++ 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/filter/divide-code-blocks.lua b/filter/divide-code-blocks.lua index df299e2..5aee241 100644 --- a/filter/divide-code-blocks.lua +++ b/filter/divide-code-blocks.lua @@ -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', [[ diff --git a/filter/style-fenced-divs.lua b/filter/style-fenced-divs.lua index d65a0ad..7af20d1 100644 --- a/filter/style-fenced-divs.lua +++ b/filter/style-fenced-divs.lua @@ -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", }, } @@ -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 diff --git a/filter/tabularx.lua b/filter/tabularx.lua index 0beba66..d368bf9 100644 --- a/filter/tabularx.lua +++ b/filter/tabularx.lua @@ -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 @@ -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 -- diff --git a/template/tcg.tex b/template/tcg.tex index 6ceef10..6e5f030 100644 --- a/template/tcg.tex +++ b/template/tcg.tex @@ -271,6 +271,7 @@ \definecolor{informative-header}{RGB}{75, 77, 78} \definecolor{informative-foreground}{RGB}{10, 10, 10} + % % code block style % @@ -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}