VaccineAndDrugEvaluationCentre / rosewood-go

Reference implementation of RoseWood
0 stars 0 forks source link

simple latex rendering #30

Open DrGo opened 5 years ago

DrGo commented 5 years ago

all new code is in single file https://github.com/VaccineAndDrugEvaluationCentre/rosewood-go/blob/latex/renderers/latex/latex_render.go there is a test in https://github.com/VaccineAndDrugEvaluationCentre/rosewood-go/blob/latex/renderers/latex/latex_render_test.go that you could run in vscode to see the generated latex code which you could c&p into a tex file to see the output. For most recent run, see https://github.com/VaccineAndDrugEvaluationCentre/rosewood-go/blob/latex/renderers/latex/tab.tex

This generate one file per table. I have not decided how to handle pulling them in one file (might use approach similar to gohugo eg user-specified preamble file and postamble file with \input table1 etc. sandwiched in between.

No markdown processing yet. Need to create a list of all characters that need to be escaped and all chars that needs to be typeset eg >=. Can you help? No cmidrule yet

styles not handled yet except that it now adds a midrule after the last header row.

Thanks,

Righolt commented 5 years ago

Some notes:

DrGo commented 5 years ago

added simple escaping so compiling won't fail. Have a look at https://github.com/VaccineAndDrugEvaluationCentre/rosewood-go/blob/latex/renderers/latex/long-table.tex and the pdf.

two issues (see complier log for error):

Righolt commented 5 years ago

I used the following packages in the latex repo (see also https://github.com/VaccineAndDrugEvaluationCentre/latex/blob/master/tables/table-sandbox.tex)

\usepackage{booktabs}
\usepackage{longtable}
\usepackage{crimson}
\usepackage[T1]{fontenc}
\usepackage{pdflscape}

longtable replaces multirow and array (not sure whether it defines it internally or calls it internally), although doesn't deal with margins.

The fontenc add will take care of > and < I think.

Margins will be hard, because Latex is meant to take care of that on it's own.

Length is dealt with by the longtable package (you just need to define lines that cannot be broken), e.g. anything that is indented should not be on a new page (I use \quad for indentation):

\multicolumn{7}{l}{Age} \\
\nopagebreak \quad 9 - 17 years & 293 (2.1\%) & 876 (2.2\%) & 0 (0.0\%) & 0 (0.0\%) & 0 (0.0\%) & 0 (0.0\%) \\
\nopagebreak \quad 18 - 30 years & 7,143 (51.5\%) & 20,975 (51.5\%) & 7 (8.6\%) & 21 (9.6\%) & 6 (0.6\%) & 17 (0.7\%) \\
\nopagebreak \quad 31 - 50 years & 5,091 (36.7\%) & 14,998 (36.8\%) & 15 (18.5\%) & 45 (20.5\%) & 174 (16.5\%) & 473 (19.1\%) \\
\nopagebreak \quad 51 - 64 years & 1,017 (7.3\%) & 2,971 (7.3\%) & 24 (29.6\%) & 71 (32.4\%) & 433 (41.0\%) & 1,071 (43.2\%) \\
\nopagebreak \quad 65+ years & 336 (2.4\%) & 882 (2.2\%) & 35 (43.2\%) & 82 (37.4\%) & 442 (41.9\%) & 920 (37.1\%) \\

Width is a different beast, I'm not sure whether there is a great solution, some options:

DrGo commented 5 years ago

just pushed the most recent changes to the latex renderer https://github.com/VaccineAndDrugEvaluationCentre/rosewood-go/blob/latex/renderers/latex/latex_render.go

Righolt commented 5 years ago

Consider adding latex items to .gitignore (see https://github.com/VaccineAndDrugEvaluationCentre/latex/blob/master/.gitignore for what I found before).

Some notes:

Righolt commented 5 years ago

tabularx seems to work

Working on example now, this may overwrite some of what I said before.

Righolt commented 5 years ago

See tex and pdf here: https://github.com/VaccineAndDrugEvaluationCentre/latex/tree/master/tables

Basically the longtable package is combined with width control.

The preamble is

\usepackage{booktabs}
\usepackage{crimson}
\usepackage[T1]{fontenc}
\usepackage{pdflscape}
\usepackage{ltablex}
\usepackage[margin=1in]{geometry}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

Tables start with

\clearpage
\newcolumntype{Z}{>{\hsize=0.25\textwidth}X}
\begin{tabularx}{\textwidth}{ZYYYYYY}
    \caption{WORK IN PROGRESS with Crimson font: Long table sandbox} \\
    \toprule

Y is a centered, reworked column set in preamble, Z will need to defined for each table with the multiplier [here 0.25] defined as 2/(N+1), with N the number of columns to have the first column as double the size). It might be possible to define additional column styles [probably need a right-aligned X column as well. (X column is a column that's size automatically.

End table is

\end{tabularx}

Look at the pdf in the other file and see what you think. (Manual mdson option could be width of first column as well, but using 2/(N+1) as default would at least lead to reasonable first guesses as long as that is possible given the content). I'm available for a call if you want to discuss.