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.

  • 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 Apr 22 '19 at 17:29
  • What specific feature from tcolorbox are you missing. Most of it is straightforward using framed and textbackground environments. – Aditya Apr 22 '19 at 22:51
  • @Aditya Breakable boxes and box shape customization by tikz since I am familiar only with tikz. – Muhammed Hashim Apr 23 '19 at 03: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. – Henri Menke Apr 23 '19 at 07: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 Apr 23 '19 at 13:04
  • @MuhammedHashim Maybe you should also bring this to the attention of the author of tcolorbox (maybe by opening an issue on GitHub: https://github.com/T-F-S/tcolorbox). – TeXnician Apr 24 '19 at 15:20

1 Answers1

7

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

Henri Menke
  • 109,596
  • 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). – Muhammed Hashim Apr 23 '19 at 03:22
  • 2
    @MuhammedHashim Yes, you can also have breakable boxes with textbackground, see e.g. this answer: https://tex.stackexchange.com/a/377261. Customization with TikZ instead of MetaFun is not possible. ConTeXt is tightly coupled to MetaFun. – Henri Menke Apr 23 '19 at 03:55
  • 2
    @HenriMenke: It is possible to use customization for framed with TikZ instead of Metapost. See https://mailman.ntg.nl/pipermail/ntg-context/2012/069802.html It is just a matter of providing a few nice helper macros. – Aditya Apr 23 '19 at 13:06
  • @Aditya That looks helpful. You should post it as an additional answer. – Henri Menke Apr 23 '19 at 20:24