Export file contaning code blocks to LaTeX

Code blocks are not exported correctly. The file:


The exported LaTeX:

which does not compile. It looks \end{alltt} cause the problem, but I don’t know why. I didn’t find detailed guide for the alltt package.

Nevertheless, the minted package should be better (it supports syntax highlighting). However, it seems it can’t be included in a newenvironment.

I guess we can update or customize the export mechanism to use minted directly and not using newenvironment?

1 Like

Could you please post here the code for the TeXmacs file (copy from a text editor the whole .tm file).

G.

The package alltt is described here: https://ctan.org/pkg/alltt?lang=en

<TeXmacs|2.1.2>

<style|generic>

<\body>
  <\cpp-code>
    #include \<less\>iostream\<gtr\>

    int main () {

    \ \ \ \ std::cout \<less\>\<less\> "Hello World!" \<less\>\<less\>
    std::endl;

    }
  </cpp-code>
</body>

<\initial>
  <\collection>
    <associate|page-medium|paper>
  </collection>
</initial>

Thanks.
I tested it, my exported file is

\documentclass{article}
\usepackage[english]{babel}
\usepackage{alltt}

%%%%%%%%%% Start TeXmacs macros
\newenvironment{tmcode}[1][]{\begin{alltt} }{\end{alltt}}
%%%%%%%%%% End TeXmacs macros

\begin{document}

\begin{tmcode}[cpp]
\#include <iostream>
int main () \{
    std::cout << "Hello World!" << std::endl;
\}
\end{tmcode}

\end{document}

which seems the same as yours, and it did compile.

1 Like

Thanks. It compiles now, not sure what caused the problem before. Switching to minted still not work, but that’s a latex problem. I can manually change those environment, but I also need to remove \ from \#, \{ and \}.