5

I am planning to move to Context, however, the fact that I'll miss some of LaTeX packages (especially tcolorbox) feels sad. That's why I asked such a question.

6
  • 3
    Unfortunately, there is not. I am using ConTeXt for a while now and really miss that package. If I want to use boxes I have to write some Metapost…
    – TeXnician
    Commented Apr 22, 2019 at 17:29
  • What specific feature from tcolorbox are you missing. Most of it is straightforward using framed and textbackground environments.
    – Aditya
    Commented Apr 22, 2019 at 22:51
  • @Aditya Breakable boxes and box shape customization by tikz since I am familiar only with tikz. Commented Apr 23, 2019 at 3:18
  • 1
    @MuhammedHashim Actually, looking through the tcolorbox code, it seems that it could be made format-independent with moderate effort. Some stuff like listings support would have to stay LaTeX-only, but PGF/TikZ does that too. Commented Apr 23, 2019 at 7:33
  • @MuhammedHashim: textbackground provides breakable boxes and both framed and textbackgrounds provide fancy backgrounds. What do you mean by shape customization? Can you give a specific example of what you are trying to achieve. Not everyone knows all the features of tcolorbox.
    – Aditya
    Commented Apr 23, 2019 at 13:04

1 Answer 1

8

You can emulate tcolorbox sufficiently well with framed, framedtext, and the MetaFun overlay mechanism.

\startuseMPgraphic{mp:tcolorbox}
  path p ; numeric w, h, o ;
  w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
  p := ((0,0) -- (0,h+2o) -- (w,h+2o) -- (w,0) -- cycle) cornered (o) ;
  fill p withcolor OverlayColor ;
  draw p withcolor OverlayLineColor withpen pencircle scaled OverlayLineWidth ;
  p := ((0,h) -- (0,h+2o) -- (w,h+2o) -- (w,h) -- cycle) cornered (o) ;
  filldraw p -- cycle withcolor OverlayLineColor ;
  draw textext.rt(\MPstring{tcolorbox}) shifted (o,h+o) withcolor white ;
  setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay[tcolorbox][\useMPgraphic{mp:tcolorbox}]

\define\setframetitle
  {\setMPtext{tcolorbox}{\strut\framedparameter{title}}}

\defineframedtext
  [tcolorbox]
  [frame=off,
   background=tcolorbox,
   backgroundcolor=white,
   framecolor=darkred,
   rulethickness=2pt,
   extras=\setframetitle]

\starttext

\starttcolorbox
  [title={Knuth},
   backgroundcolor=lightgray]

  \samplefile{knuth}

\stoptcolorbox

\stoptext

enter image description here

4
  • Thank you, but is it possible to make breakable boxes like in tcolorbox is breakable boxes and being cutomized by tikz that I am familiar with (Maybe I should learn some of MetaFun for such a purpose). Commented Apr 23, 2019 at 3:22
  • 2
    @MuhammedHashim Yes, you can also have breakable boxes with textbackground, see e.g. this answer: tex.stackexchange.com/a/377261. Customization with TikZ instead of MetaFun is not possible. ConTeXt is tightly coupled to MetaFun. Commented Apr 23, 2019 at 3:55
  • 2
    @HenriMenke: It is possible to use customization for framed with TikZ instead of Metapost. See mailman.ntg.nl/pipermail/ntg-context/2012/069802.html It is just a matter of providing a few nice helper macros.
    – Aditya
    Commented Apr 23, 2019 at 13:06
  • @Aditya That looks helpful. You should post it as an additional answer. Commented Apr 23, 2019 at 20:24

You must log in to answer this question.

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