Skip to content
This repository has been archived by the owner on May 2, 2019. It is now read-only.

Commit

Permalink
Merge pull request #405 from progit/use_pandoc_tables
Browse files Browse the repository at this point in the history
Use pandoc tables for pdf generation
  • Loading branch information
jnavila committed Apr 13, 2013
2 parents 7d3af49 + a7159ae commit fa55279
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
15 changes: 15 additions & 0 deletions en/02-git-basics/01-chapter2.markdown
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ The most interesting option is `format`, which allows you to specify your own lo


Table 2-1 lists some of the more useful options that format takes. Table 2-1 lists some of the more useful options that format takes.


<!-- Attention to translators: this is a table declaration.
The lines must be formatted as follows
<TAB><First column text><TAB><Second column text>
-->

Option Description of Output Option Description of Output
%H Commit hash %H Commit hash
%h Abbreviated commit hash %h Abbreviated commit hash
Expand Down Expand Up @@ -596,6 +601,11 @@ The `oneline` and `format` options are particularly useful with another `log` op


Those are only some simple output-formatting options to `git log` — there are many more. Table 2-2 lists the options we’ve covered so far and some other common formatting options that may be useful, along with how they change the output of the `log` command. Those are only some simple output-formatting options to `git log` — there are many more. Table 2-2 lists the options we’ve covered so far and some other common formatting options that may be useful, along with how they change the output of the `log` command.


<!-- Attention to translators: this is a table declaration.
The lines must be formatted as follows
<TAB><First column text><TAB><Second column text>
-->

Option Description Option Description
-p Show the patch introduced with each commit. -p Show the patch introduced with each commit.
--word-diff Show the patch in a word diff format. --word-diff Show the patch in a word diff format.
Expand Down Expand Up @@ -625,6 +635,11 @@ The last really useful option to pass to `git log` as a filter is a path. If you


In Table 2-3 we’ll list these and a few other common options for your reference. In Table 2-3 we’ll list these and a few other common options for your reference.


<!-- Attention to translators: this is a table declaration.
The lines must be formatted as follows
<TAB><First column text><TAB><Second column text>
-->

Option Description Option Description
-(n) Show only the last n commits -(n) Show only the last n commits
--since, --after Limit the commits to those made after the specified date. --since, --after Limit the commits to those made after the specified date.
Expand Down
37 changes: 18 additions & 19 deletions latex/makepdf
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ def pre_pandoc(string, config)
s /\`(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.\(\)\#]+)\`/, '<\1>' s /\`(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.\(\)\#]+)\`/, '<\1>'
s /(\n\n)\t(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.\(\)\#]+)\n([^\t]|\t\n)/, '\1<\2>\1' s /(\n\n)\t(http:\/\/[A-Za-z0-9\/\%\&\=\-\_\\\.\(\)\#]+)\n([^\t]|\t\n)/, '\1<\2>\1'


# Match table in markdown and change them to pandoc's markdown tables
s /(\n(\n\t([^\t\n]+)\t([^\t\n]+))+\n\n)/ do
first_col=20
t = $1.gsub /(\n?)\n\t([^\t\n]+)\t([^\t\n]+)/ do
if $1=="\n"
# This is the header, need to add the dash line
$1 << "\n " << $2 << " "*(first_col-$2.length) << $3 <<
"\n " << "-"*18 << " " << "-"*$3.length
else
# Table row : format the first column as typewriter and align
$1 << "\n `" << $2 << "`" + " "*(first_col-$2.length-2) << $3
end
end
t << "\n"
end

# Process figures # Process figures
s /Insert\s18333fig\d+\.png\s*\n.*?\d{1,2}-\d{1,2}\. (.*)/, 'FIG: \1' s /Insert\s18333fig\d+\.png\s*\n.*?\d{1,2}-\d{1,2}\. (.*)/, 'FIG: \1'
end end
Expand Down Expand Up @@ -112,25 +128,8 @@ def post_pandoc(string, config)
# Convert inline-verbatims into \texttt (which is able to wrap) # Convert inline-verbatims into \texttt (which is able to wrap)
s /\\verb(\W)(.*?)\1/ ,'\\texttt{\2}' s /\\verb(\W)(.*?)\1/ ,'\\texttt{\2}'


# Make Tables 2-1..2-3 actual tables # Style ctables
s /\\begin\{verbatim\}\n(([^\t\n]+\t.*?\n)+)(([^\t\n]*)\n)?\\end\{verbatim\}/ do s /ctable\[pos = H, center, botcap\]\{..\}/ , 'ctable[pos = ht!, caption = ~ ,width = 130mm, center, botcap]{lX}'
$cap = $4
"\\begin{table}[ht!]
\\refstepcounter{tab}
\\centering
\\label{tab:\\thetab}
\\begin{tabular}{p{2.75cm}p{8.25cm}}
\\toprule\n" <<
verbatim_sanitize($1).
gsub(/^([^\n\t]+)\t/, '{\footnotesize\texttt{\1}} & ').
gsub(/(\n)/, '\\\\\\\\\1').
sub(/\{\\footnotesize\\texttt(.*?)\n/, '{\1\midrule ').
concat("
\\bottomrule
\\end{tabular}
\\textbf{\\caption{#{$cap}}}
\\end{table}")
end


# Shaded verbatim block # Shaded verbatim block
s /(\\begin\{verbatim\}.*?\\end\{verbatim\})/m, '\begin{shaded}\1\end{shaded}' s /(\\begin\{verbatim\}.*?\\end\{verbatim\})/m, '\begin{shaded}\1\end{shaded}'
Expand Down
6 changes: 5 additions & 1 deletion latex/template.tex
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
\usepackage{booktabs} \usepackage{booktabs}
\usepackage{indentfirst} \usepackage{indentfirst}
\usepackage{framed,color} \usepackage{framed,color}
\usepackage{caption}
\captionsetup{font=bf,position=below}

\usepackage{ctable}


\definecolor{shadecolor}{gray}{0.90} \definecolor{shadecolor}{gray}{0.90}


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


\textbf{\caption{#1}} \caption{#1}
\end{figure}} \end{figure}}


\newcounter{tab}[chapter] \newcounter{tab}[chapter]
Expand Down

0 comments on commit fa55279

Please sign in to comment.