1

I'm trying to use xcoffins as a lightweight tcolorbox, like so:

demo

This works great when defining a command I can wrap content in, however I need to make this behaviour accessible through an environment, i.e. instead of \test{hi},

\begin{test}
hi
\end{test}

I am aware of the environ package, but would like to keep things as lightweight as possible. I'm hoping someone might know how this could be achieved with xcoffins, or plain LaTeX.

MWE

\documentclass{article}

\usepackage{xcolor}
\usepackage{xcoffins}

\NewCoffin\Content
\NewCoffin\SideRule

\newcommand{\test}[1]{%
  \SetVerticalCoffin\Content{\linewidth}{\noindent#1}
  \SetHorizontalCoffin\SideRule{\color{blue!70!green!70!black}\rule{1pt}{\CoffinTotalHeight\Content}}

  \JoinCoffins*\Content[l,t]\SideRule[l,t](-0.5em,0pt)
  \noindent\TypesetCoffin\Content
  \vspace*{\CoffinTotalHeight\Content}\bigskip
}

\begin{document}

\test{Hey\\there}

\end{document}
2

You can use \vcoffin_set:Nnw from the programming layer l3coffins (xcoffins is just a thin wrapper around l3coffins). \SetVerticalCoffin just provides access to \vcoffin_set:Nnn (note the n at the end) which means the contents have to be grabbed as an argument. The :Nnw version is precisely to be used in situations like this.

\documentclass{article}

\usepackage{xcolor}
\usepackage{xcoffins}

\NewCoffin\Content
\NewCoffin\SideRule

\ExplSyntaxOn
\NewDocumentEnvironment {test} { }
  {
    \vcoffin_set:Nnw \Content { \linewidth }
      \noindent \ignorespaces
  }
  {
    \vcoffin_set_end:
    \SetHorizontalCoffin\SideRule{\color{blue!70!green!70!black}\rule{1pt}{\CoffinTotalHeight\Content}}

    \JoinCoffins*\Content[l,t]\SideRule[l,t](-0.5em,0pt)
    \noindent\TypesetCoffin\Content
    \vspace*{\CoffinTotalHeight\Content}\bigskip
  }
\ExplSyntaxOff

\begin{document}

\begin{test}
Hey\\there
\end{test}

\end{document}

You could also use \NewDocumentEnvironment { test } { b }, to grab the body of the environment (that's built into LaTeX, so no packages needed), but I think \vcoffin_set:Nnw is a much better option here.

1
  • This works wonderfully! Many thanks.
    – tecosaur
    Jan 14 at 18:47

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.