CatalaLang / catala

Programming language for literate programming law specification

Home Page:https://catala-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Generated LaTeX fails to compile for tests

AltGr opened this issue · comments

Whenever trying to compile the tex obtained from a catala file containing a ```catala-test-inline section, I obtain the following error:

! LaTeX Error: Environment Shaded undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.377 \begin{Shaded}

Is it an error with the generation or do I need additional specific LaTeX packages installed ?

Oh I think this is a glitch coming from the pandoc LaTeX generation and the packages it expects to render code blocks. Let me look but I think we need to add a package in the preamble.

I remember trying to quickly work around it some time ago without success, but I don't have your skillz with LaTeX ;)

From https://pandoc.org/MANUAL.html :

When using LaTeX, the following packages need to be available (they are included with all recent versions of TeX Live): amsfonts, amsmath, lm, unicode-math, iftex, listings (if the --listings option is used), fancyvrb, longtable, booktabs, graphicx (if the document contains images), hyperref, xcolor, soul, geometry (with the geometry variable set), setspace (with linestretch), and babel (with lang). If CJKmainfont is set, xeCJK is needed. The use of xelatex or lualatex as the PDF engine requires fontspec. lualatex uses selnolig. xelatex uses bidi (with the dir variable set). If the mathspec variable is set, xelatex will use mathspec instead of unicode-math. The upquote and microtype packages are used if available, and csquotes will be used for typography if the csquotes variable or metadata field is set to a true value. The natbib, biblatex, bibtex, and biber packages can optionally be used for citation rendering. The following packages will be used to improve output quality if present, but pandoc does not require them to be present: upquote (for straight quotes in verbatim environments), microtype (for better spacing adjustments), parskip (for better inter-paragraph spaces), xurl (for better line breaks in URLs), bookmark (for better PDF bookmarks), and footnotehyper or footnote (to allow footnotes in tables).

Adding the relevant packages mentionned above here : https://github.com/CatalaLang/catala/blob/master/compiler/literate/latex.ml#L64 should do the trick

@AltGr this package provides the shaded environment : https://www.ctan.org/pkg/framed

I still have the issue, even with the framed package loaded. @denismerigoux what version of Pandoc are you using ?

Here I have 2.17.1.1, which does require the Shaded environment.
The image we use for the CI (log link above) has 3.1.2

You can test with it with docker run --rm -it registry.gitlab.inria.fr/verifisc/docker-catala

I have pandoc 2.9.2.1.

ah don't update then 😨

I confirm that for me, the following Catala source :

Le test ci-dessus doit donner le résultat suivant à l'exécution.

```catala-test-inline
$ catala Interpret --disable-warnings -s NombreDeParts1
[RESULT] Computation successful! Results:
[RESULT]
sortie =
  Impot_revenu.NombreDeParts {
    -- nombre_de_parts: 3,0
    -- abattement: 0,00 €
  }
```

Gets weaved into LaTeX into :

Le test ci-dessus doit donner le résultat suivant à l'exécution.

\begin{verbatim}
$ catala Interpret --disable-warnings -s NombreDeParts1
[RESULT] Computation successful! Results:
[RESULT]
sortie =
  Impot_revenu.NombreDeParts {
    -- nombre_de_parts: 3,0
    -- abattement: 0,00 €
  }
\end{verbatim}

With catala#master, pandoc 2.9.2.1 and TeXLive 2023, package framed version 0.96.

Yep the issue is clearly the pandoc output which differs with newer versions:

% pandoc -f markdown+multiline_tables+tex_math_dollars --mathjax -t latex <<<'```catala-test-inline
$ some test
```'       
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{$ some test}
\end{Highlighting}
\end{Shaded}

instead of using verbatim

haha ok I found it 😓
Actually when run in standalone mode pandoc defines that custom environment in the header

\newenvironment{Shaded}{}{}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.49,0.56,0.16}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
\newcommand{\BuiltInTok}[1]{\textcolor[rgb]{0.00,0.50,0.00}{#1}}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.53,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.56,0.13,0.00}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.73,0.13,0.13}{\textit{#1}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{1.00,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.25,0.63,0.44}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.02,0.16,0.49}{#1}}
\newcommand{\ImportTok}[1]{\textcolor[rgb]{0.00,0.50,0.00}{\textbf{#1}}}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.40,0.40,0.40}{#1}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.00,0.44,0.13}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.74,0.48,0.00}{#1}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.73,0.40,0.53}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.10,0.09,0.49}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.25,0.44,0.63}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.38,0.63,0.69}{\textbf{\textit{#1}}}}

(if using --no-highlight, we get back to a standard verbatim environment ; but we probably don't want that in case we have fenced blocks with other languages ?)

Fixed for now with --no-highlight (#583)