Skip to content

Commit e738104

Browse files
committed
Translate the table declarations to use pandoc table management
This change allows to get rid of the hack made on the generated latex. Moreover, writers and translators can now use markdown typesetting inside the table and it is be correctly converted. One downside is that to be processed correctly, the table must be in form of a block made of lines starting with a tab and with tab as a column separator ie matching the regex /^\t[^t^n]+\t[^\t\n]+$/. Otherwise it is not transformed to table.
1 parent 0444f53 commit e738104

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

latex/makepdf

+18-19
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,22 @@ def pre_pandoc(string, config)
7878
s /\`(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.\(\)\#]+)\`/, '<\1>'
7979
s /(\n\n)\t(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.\(\)\#]+)\n([^\t]|\t\n)/, '\1<\2>\1'
8080

81+
# Match table in markdown and change them to pandoc's markdown tables
82+
s /(\n(\n\t([^\t\n]+)\t([^\t\n]+))+\n\n)/ do
83+
first_col=20
84+
t = $1.gsub /(\n?)\n\t([^\t\n]+)\t([^\t\n]+)/ do
85+
if $1=="\n"
86+
# This is the header, need to add the dash line
87+
$1 << "\n " << $2 << " "*(first_col-$2.length) << $3 <<
88+
"\n " << "-"*18 << " " << "-"*$3.length
89+
else
90+
# Table row : format the first column as typewriter and align
91+
$1 << "\n `" << $2 << "`" + " "*(first_col-$2.length-2) << $3
92+
end
93+
end
94+
t << "\n"
95+
end
96+
8197
# Process figures
8298
s /Insert\s18333fig\d+\.png\s*\n.*?\d{1,2}-\d{1,2}\. (.*)/, 'FIG: \1'
8399
end
@@ -112,25 +128,8 @@ def post_pandoc(string, config)
112128
# Convert inline-verbatims into \texttt (which is able to wrap)
113129
s /\\verb(\W)(.*?)\1/ ,'\\texttt{\2}'
114130

115-
# Make Tables 2-1..2-3 actual tables
116-
s /\\begin\{verbatim\}\n(([^\t\n]+\t.*?\n)+)(([^\t\n]*)\n)?\\end\{verbatim\}/ do
117-
$cap = $4
118-
"\\begin{table}[ht!]
119-
\\refstepcounter{tab}
120-
\\centering
121-
\\label{tab:\\thetab}
122-
\\begin{tabular}{p{2.75cm}p{8.25cm}}
123-
\\toprule\n" <<
124-
verbatim_sanitize($1).
125-
gsub(/^([^\n\t]+)\t/, '{\footnotesize\texttt{\1}} & ').
126-
gsub(/(\n)/, '\\\\\\\\\1').
127-
sub(/\{\\footnotesize\\texttt(.*?)\n/, '{\1\midrule ').
128-
concat("
129-
\\bottomrule
130-
\\end{tabular}
131-
\\textbf{\\caption{#{$cap}}}
132-
\\end{table}")
133-
end
131+
# Style ctables
132+
s /ctable\[pos = H, center, botcap\]\{..\}/ , 'ctable[pos = ht!, caption = ~ ,width = 130mm, center, botcap]{lX}'
134133

135134
# Shaded verbatim block
136135
s /(\\begin\{verbatim\}.*?\\end\{verbatim\})/m, '\begin{shaded}\1\end{shaded}'

latex/template.tex

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
\usepackage{booktabs}
1414
\usepackage{indentfirst}
1515
\usepackage{framed,color}
16+
\usepackage{caption}
17+
\captionsetup{font=bf,position=below}
18+
19+
\usepackage{ctable}
1620

1721
\definecolor{shadecolor}{gray}{0.90}
1822

@@ -91,7 +95,7 @@
9195
\label{img:\theimg}
9296
\centering\IfFileExists{figures/\theimg.pdf}{\includegraphics[width=\maxwidth]{figures/\theimg.pdf}}{\includegraphics[width=\maxwidth]{figures/\theimg.png}}
9397

94-
\textbf{\caption{#1}}
98+
\caption{#1}
9599
\end{figure}}
96100

97101
\newcounter{tab}[chapter]

0 commit comments

Comments
 (0)