1

I'm sorry for my MWE too big. However I don't know how to make it smaller in this case. I want to use tcolorbox to frame latex code. Unless I'm mistaken this code worked under the texlive 2017 distribution. Now with Ubuntu 24.04LTS and texlive 2023 I have a slight typo that appears. here is the first mwe to make a box with title

\documentclass{minimal}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\tikzset{coltria/.style={fill=red!15!white}}

%-------------------------
%   box dédiée au code latex avec titre
%-------------------------
\newtcblisting{latex}[2][]
{empty,breakable,leftrule=5mm,left=2mm,
    frame style={fill,top color=green!75!black,bottom color=green!75!black,middle color=green},
    listing only,
    listing engine=listings,
    %       listing options={style=latexliststyle,tabsize=4,breaklines,
        listing options={tabsize=4,breaklines,
            breakindent=1.5em,columns=fullflexible},
        colback=yellow!15!white,
        %-------------------------
        % code for unbroken boxes:
        %-------------------------
        frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
            --([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
            --([yshift=5mm]frame.south east)--([xshift=-5mm]frame.south east)--cycle; },
        interior code={\path[tcb fill interior] (interior.south west)--(interior.north west)
            --([xshift=-4.8mm]interior.north east)--([yshift=-4.8mm]interior.north east)
            --([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
            --cycle; },
        attach boxed title to top center={yshift=-2mm},
        title=\fcolorbox{black}{black}{\red{#2}},
        %-------------------------
        % code for the first part of a break sequence:
        %-------------------------
        skin first is subskin of={emptyfirst}{%
            frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
                --([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
                --(frame.south east)--cycle;
                \path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
                -- +(60:2mm)-- cycle; },
            interior code={\path[tcb fill interior] (interior.south west|-frame.south)
                --(interior.north west)--([xshift=-4.8mm]interior.north east)
                --([yshift=-4.8mm]interior.north east)--(interior.south east|-frame.south)
                --cycle; },
        },
        %-------------------------
        % code for the middle part of a break sequence:
        %-------------------------
        skin middle is subskin of={emptymiddle}{%
            frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
                --(frame.north east)--(frame.south east)--cycle;
                \path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
                -- +(300:2mm) -- cycle;
                \path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
                -- +(60:2mm) -- cycle;
            },
            interior code={\path[tcb fill interior] (interior.south west|-frame.south)
                --(interior.north west|-frame.north)--(interior.north east|-frame.north)
                --(interior.south east|-frame.south)--cycle; },
        },
        %-------------------------
        % code for the last part of a break sequence:
        %-------------------------
        skin last is subskin of={emptylast}{%
            frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
                --(frame.north east)--([yshift=5mm]frame.south east)
                --([xshift=-5mm]frame.south east)--cycle;
                \path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
                -- +(300:2mm) -- cycle;
            },
            interior code={\path[tcb fill interior] (interior.south west)
                --(interior.north west|-frame.north)--(interior.north east|-frame.north)
                --([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
                --cycle; }, #1}}
        
    
\begin{document}
    
    \begin{latex}{exemple latex}
        \section{Installation sur système Linux}
        
        \begin{itemize}
            \setlength\itemsep{0.05em} %semble ok 
            \item Pour l'installation minimale, installez le paquet \textbf{texlive};
            \index{texlive@\orange{texlive}}
            
            \item Pour le support de la langue française, installez le paquet \textbf{texlive-lang-french};
            \index{texlive@\orange{texlive-lang-french}}
            
            \item Pour une compilation de greffons bien utiles, installez le paquet \textbf{texlive-latex-extra};
            \index{texlive@\orange{texlive-latex-extra}}
            \item \green{Pour l'installation complète sans se poser de question au sujet des paquets supplémentaires, installez le paquet \textbf{texlive-full}
                \index{texlive@\orange{texlive-full}}
                \footnote{Lua\LaTeX, une variante de \LaTeX{} utilisant le langage de script Lua est également installée. je vous le recommande}}.
        \end{itemize}
        
        \subsection{Installation optimale pour Ubuntu}
    \end{latex}
    

\end{document}

here there is only one error that appears here it is

97: Undefined control sequence. \end{latex}

here is the 2nd mwe to make a box this time without title

\documentclass{minimal}
\usepackage[most]{tcolorbox}
\usepackage{tikz}
\tikzset{coltria/.style={fill=red!15!white}}

    %-------------------------      
    %   box dédiée au code latex sans titre
    %-------------------------
    \newtcblisting{latex*}[1][]
    {empty,breakable,leftrule=5mm,left=2mm,
        frame style={fill,top color=green!75!black,bottom color=green!75!black,middle color=green},
        listing only,
        listing engine=listings,
        %listing options={style=latexlst,tabsize=4,breaklines,
            listing options={tabsize=4,breaklines,
                breakindent=1.5em,columns=fullflexible},
            %       keywordstyle=\color{red}},
        colback=yellow!15!white,
        %   watermark color=red!50!yellow!75!white,
        %   watermark text on=unbroken is unbroken box,
        %   watermark text on=first is first part,
        %   watermark text on=middle is middle part,
        %   watermark text on=last is last part,
        %-------------------------
        % code for unbroken boxes:
        %-------------------------      
        frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
            --([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
            --([yshift=5mm]frame.south east)--([xshift=-5mm]frame.south east)--cycle; },
        interior code={\path[tcb fill interior] (interior.south west)--(interior.north west)
            --([xshift=-4.8mm]interior.north east)--([yshift=-4.8mm]interior.north east)
            --([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
            --cycle; },
        attach boxed title to top center={yshift=-2mm},
        %-------------------------
        % code for the first part of a break sequence:
        %-------------------------
        skin first is subskin of={emptyfirst}{%
            frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
                --([xshift=-5mm]frame.north east)--([yshift=-5mm]frame.north east)
                --(frame.south east)--cycle;
                \path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
                -- +(60:2mm)-- cycle; },
            interior code={\path[tcb fill interior] (interior.south west|-frame.south)
                --(interior.north west)--([xshift=-4.8mm]interior.north east)
                --([yshift=-4.8mm]interior.north east)--(interior.south east|-frame.south)
                --cycle; },
        },
        %-------------------------
        % code for the middle part of a break sequence:
        %-------------------------
        skin middle is subskin of={emptymiddle}{%
            frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
                --(frame.north east)--(frame.south east)--cycle;
                \path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
                -- +(300:2mm) -- cycle;
                \path[coltria] ([xshift=2.5mm,yshift=1mm]frame.south west) -- +(120:2mm)
                -- +(60:2mm) -- cycle;
            },
            interior code={\path[tcb fill interior] (interior.south west|-frame.south)
                --(interior.north west|-frame.north)--(interior.north east|-frame.north)
                --(interior.south east|-frame.south)--cycle; },
        },
        %-------------------------
        % code for the last part of a break sequence:
        %-------------------------
        skin last is subskin of={emptylast}{%
            frame code={\path[tcb fill frame] (frame.south west)--(frame.north west)
                --(frame.north east)--([yshift=5mm]frame.south east)
                --([xshift=-5mm]frame.south east)--cycle;
                \path[coltria] ([xshift=2.5mm,yshift=-1mm]frame.north west) -- +(240:2mm)
                -- +(300:2mm) -- cycle;
            },
            interior code={\path[tcb fill interior] (interior.south west)
                --(interior.north west|-frame.north)--(interior.north east|-frame.north)
                --([yshift=4.8mm]interior.south east)--([xshift=-4.8mm]interior.south east)
                --cycle; }, #1}}    
    
    
\begin{document}
    \begin{latex*}
        \section{Installation sur système Linux}
        
        \begin{itemize}
            \setlength\itemsep{0.05em} %semble ok 
            \item Pour l'installation minimale, installez le paquet \textbf{texlive};
            \index{texlive@\orange{texlive}}
            
            \item Pour le support de la langue française, installez le paquet \textbf{texlive-lang-french};
            \index{texlive@\orange{texlive-lang-french}}
            
            \item Pour une compilation de greffons bien utiles, installez le paquet \textbf{texlive-latex-extra};
            \index{texlive@\orange{texlive-latex-extra}}
            \item \green{Pour l'installation complète sans se poser de question au sujet des paquets supplémentaires, installez le paquet \textbf{texlive-full}
                \index{texlive@\orange{texlive-full}}
                \footnote{Lua\LaTeX, une variante de \LaTeX{} utilisant le langage de script Lua est également installée. je vous le recommande}}.
        \end{itemize}
        
        \subsection{Installation optimale pour Ubuntu}
    \end{latex*}
\end{document}

this time the beginning of the text inside the box is eaten the word section is missing. Can you enlighten me on these 2 anomalies? I'm almost there, because it produces almost my 2 boxes. note: I am forced to compile in lualatex in my project for other reasons external to my question could you help me to understand what is about?

1 Answer 1

2

To begin with, \red is undefined and produces an error also with TL 2017. If I define it by

\newcommand{\red}[1]{\textcolor{red}{#1}}

the file compiles, but you lose all accented characters. With TL 2017 I get

wrong output

which is obviously unacceptable. If I compile with TL 2023, I get

! LaTeX Error: Invalid UTF-8 byte sequence (�\lst@EC�).

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.1         \section{Installation sur système
                                               Linux}

which makes me think that your file is coded as Latin-1. Indeed, if I convert your text in a Latin-1 encoded document (StackExchange uses UTF-8) and add

\usepackage[latin1]{inputenc}

the run succeed.

success

However, you should go away from Latin-1 (and adopt UTF-8). There are still problems with listing and extended character sets, but there are several posts on the site to fix them.

Or switch to minted.

1
  • ok thanks I hadn't seen this \red declaration thing. It's the difficulty of getting out of the code of a big project to make a MWE. On the other hand my source file is coded in utf8 and I don't lose the accented characters on my PC, it's strange what happened
    – Manmax
    Commented 4 hours ago

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .