当一个句子可能长达几行时,我该如何框定段落中的单个句子?就像这样,\color
但同时提供背景颜色、框架、样式等。这个想法是为内联代码提供一种格式,与\type
忽略输入空格不同。
\color
工作正常,但只设置前景色\framed
不换行\type
换行但只设置前景色。与此不同,\color
它不会忽略输入空格。\start...stoptextbackground
即使用作left=
和right=
的参数,也会强制产生一个新块\setuptype
。\framed
实际上并没有在使用时包装输入\type
:\setuptype[command=\mtc] \define[1]\mtc{% \dontleavehmode{\framed[frame=on, background=color, background-color=orange, ]{#1}}}
这就是我所说的“忽略输入空格”的意思:
\setuptype[color=red,style=\tf]
\starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been \type{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been \color[red]{the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries}, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
\stoptext
虽然我猜这并不重要,因为我可以做到这一点,但基于公认的答案:
\definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]
\starttext
Lorem Ipsum is simply dummy text of the printing and typesetting industry.
Lorem Ipsum has been \starttextbackground[mtcframed]the industry's standard dummy text ever since the 1500s,
when an unknown printer took a galley of type and scrambled it to make a type
specimen book. It has survived not only five centuries\stoptextbackground, but also the leap into
electronic typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum passages,
and more recently with desktop publishing software like Aldus PageMaker
including versions of Lorem Ipsum.
\stoptext
然后定义一个新的宏以与其他样式命令保持一致:
\define[1]\mtc{\starttextbackground[mtcframed]#1\stoptextbackground}
编辑:
英语中也存在轻微的框满问题。公平地说,这仅与使用 monotype 字体有关。不幸的是,当文本溢出框架时,这个问题非常明显。我该如何解决这个问题?例如,使用以下任一方法:
\unprotect
\defineinterfacevariable{collapse}{collapse}
\setvalue{\??typingspace\v!collapse}{\def\obeyedspace{\unskip\space}}
\protect
\definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text,
]
\define[1]\mtcA{\starttextbackground[mtcframed]\tt#1\stoptextbackground}
\definetype[mtcB]
[space=collapse,
left={\starttextbackground[mtcframed]},
right={\stoptextbackground},
]
\definetype[...][space=collapse...]
还有什么理由比 更倾向于 吗define[1]\mtc{...}
?前者很有趣也很有用,但似乎过于复杂。
答案1
\start...\stoptextbackground
是正确的做法,但您必须设置location=text
。为了折叠单词间距,我定义了一种新的间距方法collapse
并在中使用它\setuptype
。我还对单词间距添加了一点拉伸和收缩,以便更好地换行。
% The original version, which only collapses interword spaces.
%\unprotect
%\defineinterfacevariable{collapse}{collapse}
%\setvalue{\??typingspace\v!collapse}{\def\obeyedspace{\unskip\space}}
%\protect
% The updated version, which in addition adds stretch and shrink
\unprotect
\defineinterfacevariable{collapse}{collapse}
\setvalue
{\??typingspace\v!collapse}%
{\def\obeyedspace{\unskip
\hskip\interwordspace
plus .5\interwordspace
minus .5\interwordspace\relax}}
\protect
\definetype
[mtc]
[left={\starttextbackground[mtcframed]},
right={\stoptextbackground},
space=collapse]
\definetextbackground
[mtcframed]
[frame=on,
framecolor=black,
backgroundcolor=orange,
rulethickness=1pt,
location=text]
\starttext
Lorem Ipsum is simply dummy text of the printing and typesetting
industry. Lorem Ipsum has been \mtc{the industry's standard dummy
text ever since the 1500s, when an unknown printer took a galley of
type and scrambled it to make a type specimen book. It has survived
not only five centuries}, but also the leap into electronic
typesetting, remaining essentially unchanged. It was popularised in
the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like
Aldus PageMaker including versions of Lorem Ipsum.
\stoptext