3

How to get the same result of \shadowbox in LaTeX with ConTeXt ?

%\usepackage{fancybox}
\shadowbox{text}

enter image description here

This is my atttempt to use Metapost, this my MWE :

\setupcolors[state=start]
\usecolors[crayola]
\startuniqueMPgraphic{cadre}
 path q; q := (0.5,-1) -- (OverlayWidth+0.5,-1) -- (OverlayWidth+0.5, OverlayHeight) -- (0.5, OverlayHeight) --   (0.5,-1) -- cycle;
 path p; p := (0,0) -- (OverlayWidth,0) -- (OverlayWidth, OverlayHeight) -- (0, OverlayHeight) --   (0,0);
  fill q withpen pencircle scaled 5pt withcolor \MPcolor{black} ;
  fill p withpen pencircle scaled 1pt withcolor gray ;
 setbounds currentpicture to boundingbox OverlayBox;
 \stopuniqueMPgraphic
\defineoverlay[cadre][\useMPgraphic{cadre}]
 \defineframedtext[shadowbox][frame=off,background=cadre,width=\makeupwidth]

 \starttext
  
 \startshadowbox
  \input knuth
  \stopshadowbox

  \stoptext
2
  • Could you show what you are willing to do? Some ConTeXt users don't have LaTeX installed. Btw, you are using metapost: uniqueMPgraphic is a metafun command. EDIT: an example of shadowbox here: tex.stackexchange.com/questions/185051/…
    – sztruks
    Commented Apr 10, 2021 at 9:42
  • The link show exactly what I want.This my attempt to use Metapost, I do not know if it is correct !
    – Aviroum
    Commented Apr 10, 2021 at 12:02

1 Answer 1

2

I'm not sure whether or not it counts as a duplicate, but I'll post an answer if helpful. For an example of how defining your own MetaPost backgrounds, you could look at this answer by Wolfgang Schuster. Options for text background alternatives are, e.g., always (applied to the whole text), paragraph and text (applies to words).

In the MetaPost side, boundingbox is a macro to draw, as you might imagine, the bounding box of each page/paragraph/line and nofmultipars is just the number of units to handle. In our case, always only breaks across pages.

%\setuppapersize[A6]
\startuseMPgraphic{shadowed}
begingroup;
    path MyFrame, MyShadow;
    numeric MyThickness; MyThickness := 4bp;
    for i=1 upto nofmultipars:
        MyFrame := boundingbox multipars[i] enlarged (EmWidth,EmWidth);
        MyShadow := MyFrame shifted (1/2MyThickness*(1,-1));
        draw MyFrame;
        draw (
            (MyThickness*right + llcorner MyShadow)
            --lrcorner MyShadow
            --(MyThickness*down + urcorner MyShadow)
            )
        withpen pensquare scaled MyThickness;
    endfor 
endgroup;
\stopuseMPgraphic

\definetextbackground
  [shadowed]
  [mp=shadowed,
   location=always]

\starttext
\startshadowed
\input knuth
\stopshadowed
\stoptext

enter image description here

1
  • Thank you @Jairo A. del Rio, that's exactly what I want !
    – Aviroum
    Commented Apr 10, 2021 at 13:14

You must log in to answer this question.

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