ConTeXt 和 Metafun:以计数器作为覆盖部分的框架枚举

ConTeXt 和 Metafun:以计数器作为覆盖部分的框架枚举

如何制作一个enumeration计数器enumeration出现在用 Metafun 装饰的框架内?

这个想法是为了得到与 Metafun 手册第 144 页上的示例类似的东西:

在此处输入图片描述

除了“Zapf(1)”是一个计数器而不是手动标签之外。

以下是使用手动框架重现示例的代码:

\startuseMPgraphic{FunnyFrame}
  picture p ; numeric w, h, o ;
  p := textext.rt(\MPstring{FunnyFrame}) ;
  w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
  p := p shifted (2o,h-ypart center p) ; draw p ;
  drawoptions (withpen pencircle scaled 1pt withcolor .625red) ;
  draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner p,h) ;
  draw boundingbox p ;
  setbounds currentpicture to unitsquare xyscaled(w,h) ;
\stopuseMPgraphic

\defineoverlay[FunnyFrame][\useMPgraphic{FunnyFrame}]
\defineframedtext[FunnyText][frame=off,background=FunnyFrame]
\def\StartFrame{\startFunnyText}
\def\StopFrame {\stopFunnyText }
\def\FrameTitle#1%
{\setMPtext{FunnyFrame}{\hbox spread 1em{\hss\strut#1\hss}}}
\setMPtext{FunnyFrame}{}

\starttext

\FrameTitle{Zapf (1)}
\StartFrame
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\StopFrame

\stoptext

我已经取得足够的进展来回答这个问题,但我仍然不确定这是否是正确的方法。

答案1

使用\wrappedcurrentconstruction而不是MPstring/MPtext。使用\wrappedcurrentconstruction,引用也能正常工作。

\startuseMPgraphic{FunnyFrame}
    picture p ; numeric w, h, o ;
    p := textext.rt("\wrappedcurrentconstruction");

    w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
    p := p shifted (2o,h-ypart center p); 
    draw p ;

    path b;
    b := boundingbox p enlarged (o/10);

    drawoptions (withpen pencircle scaled 1pt withcolor .625red) ;
    draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner b,h) ;
    draw b;

    setbounds currentpicture to OverlayBox ;
\stopuseMPgraphic

\defineoverlay[FunnyFrame][\useMPgraphic{FunnyFrame}]

\defineframedtext
  [FunnyFramedText]
  [
    frame=off,
    background=FunnyFrame,
    offset=\bodyfontsize,
    width=\textwidth,
  ]

\defineenumeration[Counter]
  [
    alternative=empty,
    before=\startFunnyFramedText,
    after=\stopFunnyFramedText,
  ]

\starttext
\startCounter
  Coming back to the use of typefaces in electronic
  publishing: many of the new typographers receive their
  knowledge and information about the rules of typography from
  books, from computer magazines or the instruction manuals
  which they get with the purchase of a PC or software.
\stopCounter

\startCounter
  Coming back to the use of typefaces in electronic
  publishing: many of the new typographers receive their
  knowledge and information about the rules of typography from
  books, from computer magazines or the instruction manuals
  which they get with the purchase of a PC or software.
\stopCounter
\stoptext

在此处输入图片描述

答案2

\getnumber实际上,答案依赖于使用和省略默认标签来引用框架内的计数器enumeration

% Code from manual
\startuseMPgraphic{FunnyFrame}
  picture p ; numeric w, h, o ;
  p := textext.rt(\MPstring{FunnyFrame}) ;
  w := OverlayWidth ; h := OverlayHeight ; o := BodyFontSize ;
  p := p shifted (2o,h-ypart center p) ; draw p ;
  drawoptions (withpen pencircle scaled 1pt withcolor .625red) ;
  draw (2o,h)--(0,h)--(0,0)--(w,0)--(w,h)--(xpart urcorner p,h) ;
  draw boundingbox p ;
  setbounds currentpicture to unitsquare xyscaled(w,h) ;
\stopuseMPgraphic

\defineoverlay[FunnyFrame][\useMPgraphic{FunnyFrame}]
\defineframedtext[FunnyText][frame=off,background=FunnyFrame]
\def\FrameTitle#1%
{\setMPtext{FunnyFrame}{\hbox spread 1em{\hss\strut#1\hss}}}
\setMPtext{FunnyFrame}{}

% Add the enumeration
\defineenumeration
  [Counter]
  [text=,
   alternative=empty,
   before={\FrameTitle{Counter \getnumber[Counter]} 
           \startFunnyText},
   after={\stopFunnyText}]

\starttext

\startCounter
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\stopCounter

\startCounter
Coming back to the use of typefaces in electronic
publishing: many of the new typographers receive their
knowledge and information about the rules of typography from
books, from computer magazines or the instruction manuals
which they get with the purchase of a PC or software.
\stopCounter

\stoptext

编辑:alternative=inleft按照alternative=empty评论替换。

结果:

在此处输入图片描述

相关内容