1

Is there a way to factorize the following code in which the only difference between the environments doclatex and doclatex-flat is about the use of listing side text?

\documentclass[12pt]{article}

\RequirePackage{tcolorbox}

\tcbuselibrary{minted, breakable}

\newtcblisting{doclatex}{%
    breakable,
    sharp corners,
    left   = 1mm, right = 1mm,
    bottom = 1mm, top   = 1mm,
    listing side text
}

\newtcblisting{doclatex-flat}{
    breakable,
    sharp corners,
    left   = 1mm, right = 1mm,
    bottom = 1mm, top   = 1mm,
}

\begin{document}

\begin{doclatex}
$just + A = test$
\end{doclatex}

\begin{doclatex-flat}
$just + A = test$
\end{doclatex-flat}

\end{document}
2
  • 2
    You should be able to use \tcbset to define a style which defines the common settings and then can then be used in two spots. Jul 13 at 9:14
  • @PeterGrill Ok, I look at that, and thereafter I try to answer my own question. Thanks!
    – projetmbc
    Jul 13 at 9:16
1

tcolorbox's key-val scheme is from pgfkeys, which is auto loaded by either pgf or tikz. So you can define a style key using /.style key handler.

\documentclass[12pt]{article}

\RequirePackage{tcolorbox}

\tcbuselibrary{minted, breakable}

\tcbset{
    doc latex common/.style={
        breakable,
        sharp corners,
        left   = 1mm, right = 1mm,
        bottom = 1mm, top   = 1mm,
    }
}

\newtcblisting{doclatex}{%
    doc latex common,
    listing side text
}

\newtcblisting{doclatex-flat}{
    doc latex common,
    bottom = 1mm, top   = 1mm,
}

\begin{document}

\begin{doclatex}
$just + A = test$
\end{doclatex}

\begin{doclatex-flat}
$just + A = test$
\end{doclatex-flat}

\end{document}
1
  • Great! Thanks a lot!
    – projetmbc
    Jul 13 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.