1

I'd like to do call-outs on a tcolorbox like the ones in this diagram from the longfbox documentation's Breakable Content Section.

I've got my whole document using tcolorbox and pstricks but can't figure out how to make them work together. I think I need to imbed pstricks nodes inside the boxes somehow, but they are verbatim-style boxes so I'm at a loss. (Listings using the minted package inside the tcolorboxes.)

I did find this question that might help, but it is using Tikz and I'd rather stick with pstricks as I'm more familiar and comfortable with it. Can I embed pstricks in an overlay somehow as well? Would this help me pinpoint parts of a line of code within the main listing box?

Similarly this question holds promise, but is using Tikz and won't work with breakable boxes which all of mine are. This one pinpoints whole lines by line number, but I need parts of a line to show associativity of operations within the statement.

Details: I usually use underbracing on the board to draw this, but am producing some notes for public consumption and would like it to look similarly in the PDF.

Here's a MWE for a line and the idea I'm after but can't get to work:

\documentclass{article}

\usepackage{minted}
\usepackage[minted]{tcolorbox}
\tcbuselibrary{skins,breakable,listings,xparse,raster}

                   % tcb  minted
\NewTCBListing{Cpp}{ O{} !O{} }{%
                       listing engine=minted,
                       listing only,
                       minted language=cpp,
                       minted options={style=default,
                                       autogobble,
                                       %showspaces,
                                       tabsize=4,
                                       #2},
                       skin=standard,
                       breakable,
                       #1}

\newmintinline[CppInline]{cpp}{autogobble,tabsize=4,style=default}
\newcommand{\code}[1]{\leavevmode\CppInline`#1`}

\begin{document}

    Here's a line of code, for instance:

\begin{Cpp}[]
    cin >> r1 >> r2 >> r3;
\end{Cpp}

    I'd like underbraces below \code{cin >> r1} with a label saying
    \code{cin}.  And likewise another underbrace below that \code{cin} over to
    the \code{r2}.  Finally one connecting that 2$^{\textrm{}nd}$ brace's
    \code{cin} to the \code{r3}.

\end{document}

It needs pygmentize installed with python and the -shell-escape command-line argument to the latex command.

Here is the result:

Sample Output

Any thoughts welcome!

3
  • Please add an example of what you want --- even a code that fails but that we can copy and compile. Otherwise, it is almost impossible to solve your problem...
    – Rmano
    May 26, 2023 at 16:34
  • I've added an MWE and pic. Hope this helps!
    – Craie
    May 26, 2023 at 16:50
  • Maybe something with tikzmark? Like tex.stackexchange.com/questions/657375/…
    – Rmano
    May 26, 2023 at 18:30

1 Answer 1

1

with some tricky code you can create two invisible nodes. Run with lualatex:

\documentclass{article}
\usepackage{pstricks-add}
\usepackage{minted}
\usepackage[minted]{tcolorbox}
\tcbuselibrary{skins,breakable,listings,xparse,raster}

% tcb  minted
\NewTCBListing{Cpp}{ O{} !O{} }{%
    listing engine=minted,
    listing only,
    minted language=cpp,
    minted options={style=default,
        autogobble,
        %showspaces,
        tabsize=4,
        #2},
    skin=standard,
    breakable,
    #1}

\newmintinline[CppInline]{cpp}{autogobble,tabsize=4,style=default}
\newcommand{\code}[1]{\leavevmode\CppInline`#1`}

\begin{document}
    
    Here's a line of code, for instance:
    

\begin{Cpp}[]
        cin >> r1 >> r2 >> r3;
\end{Cpp}

\vspace{-5.5ex}
{\ttfamily\rnode{A}{\hphantom{cin}}\hphantom{ >> }\rnode{B}{\hphantom{r1}}}
\psbrace[linecolor=red,ref=lC,rot=90](A)(B){Text}
    
\vspace{10mm}
    I'd like underbraces below \code{cin >> r1} with a label saying
    \code{cin}.  And likewise another underbrace below that \code{cin} over to
    the \code{r2}.  Finally one connecting that 2$^{\textrm{}nd}$ brace's
    \code{cin} to the \code{r3}.
    
\end{document}

enter image description here

1
  • I ended up with something much like this. I didn't think to make hphantom text nodes over the top, though. Thanks for that idea! I was just shifting arbitrary coordinates in a pspicture for some time trying to make it line up.
    – Craie
    May 27, 2023 at 20:11

You must log in to answer this question.

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