
Ich habe einen Befehl zur Inline-Codehervorhebung mit tcbox und mintedinline erstellt, aber ich stoße auf ein Problem. Wenn ich versuche, nur ein # zu schreiben, wird es als ## dargestellt. Ich habe mit verschiedenen Optionen für tcbox experimentiert, aber nichts scheint das Problem zu lösen. Interessanterweise funktioniert es wie erwartet, wenn ich nur mintedinline verwende. Daher glaube ich nicht, dass das Problem an meiner \setminted-Konfiguration liegt.
Ich bin für alle Erkenntnisse und Vorschläge zur Lösung dieses Problems sehr dankbar.
Minimaler Latex-Code:
\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}
\usepackage{tcolorbox}
\definecolor{codeinlineBlue}{HTML}{CFE2FC}
\newcommand\mystrut{\rule[-2.5pt]{0pt}{12pt}}
\newcommand{\codeinline}[2][text]{%
\tcbox[
on line,
boxsep=0pt,
left=2pt,
right=2pt,
top=0pt,
bottom=0pt,
enlarge top initially by=-4pt,
enlarge bottom by=-4pt,
enlarge right by=-4pt,
enlarge left by=-2pt,
opacityframe=0,
colback=codeinlineBlue,
fontupper={\ttfamily\mystrut},
fontlower={\ttfamily\mystrut}]
{\mintinline{#1}{#2}}
}
\begin{document}
Text before code \codeinline{int main() \{ return 0; \}}, text after. Problem: \codeinline{#}.
This works as expected: \mintinline{text}{#}
\end{document}
Antwort1
Sie sollten das Argument wörtlich erfassen (aber Sie können es nicht \codeinline
als Argument für einen anderen Befehl verwenden). Verwenden Sie dazu \NewTotalTCBox
.
\documentclass{article}
\usepackage{xcolor}
\usepackage{minted}
\usepackage{tcolorbox}
\tcbuselibrary{xparse}
\definecolor{codeinlineBlue}{HTML}{CFE2FC}
\newcommand\mystrut{\rule[-2.5pt]{0pt}{12pt}}
\NewTotalTCBox{\codeinline}{O{text}v}{
on line,
boxsep=0pt,
left=2pt,
right=2pt,
top=0pt,
bottom=0pt,
enlarge top initially by=-4pt,
enlarge bottom by=-4pt,
enlarge right by=-4pt,
enlarge left by=-2pt,
opacityframe=0,
colback=codeinlineBlue,
fontupper={\ttfamily\mystrut},
%fontlower={\ttfamily\mystrut},
}{\mintinline{#1}{#2}}
\begin{document}
Text before code \codeinline{int main() \{ return 0; \}},
text after. Problem: \codeinline{#}.
This works as expected: \mintinline{text}{#}
\end{document}