-
Hi, thanks in advance for your help. I try to style and add code highlight to the fenced blocks of code from markdown to LaTex. I successfully setup an override for the I tried to use Do you have any idea how I could achieve that ? tex file:
test.md file: print("hello") int main(int ac, char** av)
{
return 0;
} if (a > 3) {
moveShip(5 * gravity, DOWN);
} |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 10 replies
-
In your definition of You must always specify a lexer, so that |
Beta Was this translation helpful? Give feedback.
-
AnswerAfter @Witiko 's help. main.tex: % Create a new environement "codeblock"
\newtcolorbox{codeblock}[2][]{
title={#2},
fonttitle=\scriptsize,
leftrule=1mm,
rightrule=0mm,
toprule=0mm,
bottomrule=0mm,
arc=0mm,
#1}
% Override the renderer of fenced code blocs
\ExplSyntaxOn% enable LaTex3 syntax
\global\def\markdownRendererInputFencedCode#1#2#3{%
\catcode`\#=6\relax
\begin{codeblock}{ #2 }
\tl_if_empty:nTF
{ #2 }% if the second argument (fence block "title" is empty)
{ \markdownRendererInputVerbatim{#1} }% render regular verbatim
{ \inputminted{#2}{#1} }% else render minted text
\end{codeblock}
\catcode`\#=12\relax
}
\ExplSyntaxOff% disable LaTex3 syntax
Resulttest-language.md:
test-no-language.md:
|
Beta Was this translation helpful? Give feedback.
Answer
After @Witiko 's help.
Now the renderer override
\markdownRendererInputFencedCode
will use the minted package only if the fenced block "title" is present, using it as a language for theminted
package while using our own environment to wrap the style of the fenced code bloc.main.tex: