这是来自带圆角的文本框突出显示(基于灵魂)期望的最终结果是一种“带圆圈的文本”,就像用铅笔注释文本一样。
我自己回答了这个问题,基于 Antal Spector-Zabusky 的方法LaTeX 中的酷炫文本突出显示。结果很酷,但有一个重要的限制是它不允许分页。它不允许,因为该方法依赖于soul
提供坐标并让我们tikz
完成所有绘图。Antal 的答案需要这样做,因为路径所需的不规则性(在绘图中有意义)取决于来自的装饰tikz
。
好吧,我正在寻找“不那么酷”的东西,并且对文本上方和下方的直线感到满意。为此,我可以依靠soul
而不是tikz
绘制它们,从而保留分页功能。然后,tikz
仅用于绘制角落。
soul
我最初的想法是相同的,但基于的驱动程序从头开始尝试\ul
。下面的代码很接近,但不完全一样。我无法说服自己\SOUL@everyspace
也画出上面的线。
问题的关键似乎在于:
\def\SOUL@tceveryspace#1{%
\SOUL@ulcolor{
#1%
\SOUL@tcleaders
\hskip\spaceskip
}%
\null
}
\SOUL@tcleaders
实际绘图在哪里\hrule
:
\def\SOUL@tcleaders{%
\leaders\hrule\@depth\SOUL@tcdp\@height\SOUL@tcht\relax
}
有没有办法hrules
在这一步绘制两者(底部和顶部)?
完整代码如下:
\documentclass[12pt]{scrartcl}
\usepackage{soulutf8}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing}
\newlength\LineWidth
\setlength\LineWidth{1pt}
\newlength\baseliney
\setlength\baseliney{.45ex}
\newlength\heighty
\newcommand\opac{0.35}
\colorlet{HLcolor}{gray}
\setul{.325ex}{\LineWidth}
\colorlet{ulcolor}{gray!35}
\setulcolor{ulcolor}
\makeatletter
\newdimen\SOUL@tcdp
\newdimen\SOUL@tcht
\newdimen\SOUL@tchdp
\newdimen\SOUL@tchht
\def\SOUL@tcleaders{%
\leaders\hrule\@depth\SOUL@tcdp\@height\SOUL@tcht\relax
}
\def\SOUL@tcheaders{%
\leaders\hrule\@depth\SOUL@tchdp\@height\SOUL@tchht\relax
}
\def\SOUL@tcunderline#1{{%
\setbox\z@\hbox{#1}%
\dimen@=\wd\z@
\dimen@i=\SOUL@uloverlap
\advance\dimen@2\dimen@i
\rlap{%
\null
\kern-\dimen@i
\SOUL@ulcolor{\SOUL@tcleaders\hskip\dimen@}%
}%
\rlap{%
\null
\kern-\dimen@i
\SOUL@ulcolor{\SOUL@tcheaders\hskip\dimen@}%
}%
\unhcopy\z@
}}
\def\SOUL@tcpreamble{%
\setlength{\heighty}{\f@size pt}%
\SOUL@tcdp=\SOUL@uldepth
\SOUL@tcht=-\SOUL@tcdp
\advance\SOUL@tcdp\SOUL@ulthickness
\SOUL@tchdp=-\heighty
\advance\SOUL@tchdp\SOUL@tcdp
\advance\SOUL@tchdp-\SOUL@ulthickness
\SOUL@tchht=-\SOUL@tchdp
\advance\SOUL@tchdp\SOUL@ulthickness
\spaceskip\SOUL@spaceskip
\begin{tikzpicture}[decoration={bent,aspect=.3}, overlay]
\draw[decorate,HLcolor,line width=\LineWidth,opacity=\opac] ($(0,-\baseliney)$) -- ($(0,-\baseliney+\heighty)$) ;
\end{tikzpicture}%
}
\def\SOUL@tceverysyllable{%
\SOUL@tcunderline{%
\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern
}%
}
\def\SOUL@tceveryspace#1{%
\SOUL@ulcolor{
#1%
\SOUL@tcleaders
\hskip\spaceskip
}%
\null
}
\def\SOUL@tceveryhyphen{%
\discretionary{%
\unkern
\SOUL@tcunderline{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
}%
}{}{}%
}
\def\SOUL@tceveryexhyphen#1{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@tcunderline{#1}%
\discretionary{}{}{%
\SOUL@setkern\SOUL@charkern
}%
}
\def\SOUL@tcpostamble{%
\begin{tikzpicture}[decoration={bent,aspect=.3}, overlay]
\draw[decorate,HLcolor,line width=\LineWidth,opacity=\opac] ($(0,-\baseliney+\heighty)$) -- ($(0,-\baseliney)$) ;
\end{tikzpicture}%
}
\def\SOUL@tcsetup{%
\SOUL@setup
\let\SOUL@preamble\SOUL@tcpreamble
\let\SOUL@everysyllable\SOUL@tceverysyllable
\let\SOUL@everyspace\SOUL@tceveryspace
\let\SOUL@everyhyphen\SOUL@tceveryhyphen
\let\SOUL@everyexhyphen\SOUL@tceveryexhyphen
\let\SOUL@postamble\SOUL@tcpostamble
}
\DeclareRobustCommand*\textcirc{\SOUL@tcsetup\SOUL@}
\makeatother
\begin{document}
\vspace*{15cm}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. \textcirc{Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas.} Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida
placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac,
nulla. Curabitur auctor semper nulla. \textcirc{Donec varius orci}
eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis,
diam. Duis eget orci sit amet orci dignissim rutrum. Nam dui ligula,
\textcirc{fringilla a, euismod sodales, sollicitudin vel}, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae,
ultricies et, tellus. \textcirc{Donec aliquet, tortor sed accumsan
bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi.}
Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec
ante. \ul{Pellentesque a nulla.} \textcirc{Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus.}
Aliquam tincidunt urna. Nulla ullamcorper vestibulum
turpis. Pellentesque cursus luctus mauris.
\end{document}
目前的结果是:
也就是说,除了空格上方的线条外,其他一切都已就位。有什么想法可以实现它们吗?
答案1
您已经完成了所有工作。我只是做了一些改动\SOUL@tceveryspace
(说实话,我根本没有阅读其余的代码)。该命令本质上使用了\leaders\hrule\hskip\spaceskip
,这意味着“制作一条水平线,其行为类似于长度为 的胶水\spaceskip
。特别是,胶水允许换行,并且在换行时会被删除(就像普通空格一样)。为了在上方和下方都有线条,我只需使用一个引线、一个负空间以返回原始位置并在顶部使用另一个引线。您可以看到,在我的第一个线条之后,所有内容都正确拉伸了\begin{document}
。
\documentclass[12pt]{scrartcl}
\usepackage{soulutf8}
\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathmorphing}
\newlength\LineWidth
\setlength\LineWidth{1pt}
\newlength\baseliney
\setlength\baseliney{.45ex}
\newlength\heighty
\newcommand\opac{0.35}
\colorlet{HLcolor}{gray}
\setul{.325ex}{\LineWidth}
\colorlet{ulcolor}{gray!35}
\setulcolor{ulcolor}
\makeatletter
\newdimen\SOUL@tcdp
\newdimen\SOUL@tcht
\newdimen\SOUL@tchdp
\newdimen\SOUL@tchht
\def\SOUL@tcleaders{%
\leaders\hrule\@depth\SOUL@tcdp\@height\SOUL@tcht\relax
}
\def\SOUL@tcheaders{%
\leaders\hrule\@depth\SOUL@tchdp\@height\SOUL@tchht\relax
}
\def\SOUL@tcunderline#1{{%
\setbox\z@\hbox{#1}%
\dimen@=\wd\z@
\dimen@i=\SOUL@uloverlap
\advance\dimen@2\dimen@i
\rlap{%
\null
\kern-\dimen@i
\SOUL@ulcolor{\SOUL@tcleaders\hskip\dimen@}%
}%
\rlap{%
\null
\kern-\dimen@i
\SOUL@ulcolor{\SOUL@tcheaders\hskip\dimen@}%
}%
\unhcopy\z@
}}
\def\SOUL@tcpreamble{%
\setlength{\heighty}{\f@size pt}%
\SOUL@tcdp=\SOUL@uldepth
\SOUL@tcht=-\SOUL@tcdp
\advance\SOUL@tcdp\SOUL@ulthickness
\SOUL@tchdp=-\heighty
\advance\SOUL@tchdp\SOUL@tcdp
\advance\SOUL@tchdp-\SOUL@ulthickness
\SOUL@tchht=-\SOUL@tchdp
\advance\SOUL@tchdp\SOUL@ulthickness
\spaceskip\SOUL@spaceskip
\begin{tikzpicture}[decoration={bent,aspect=.3}, overlay]
\draw[decorate,HLcolor,line width=\LineWidth,opacity=\opac] ($(0,-\baseliney)$) -- ($(0,-\baseliney+\heighty)$) ;
\end{tikzpicture}%
}
\def\SOUL@tceverysyllable{%
\SOUL@tcunderline{%
\the\SOUL@syllable
\SOUL@setkern\SOUL@charkern
}%
}
\def\SOUL@tceveryspace#1{%
\SOUL@ulcolor{
#1%
\SOUL@tcleaders
\hskip\spaceskip
\hskip-\spaceskip
\SOUL@tcheaders
\hskip\spaceskip
}%
\null
}
\def\SOUL@tceveryhyphen{%
\discretionary{%
\unkern
\SOUL@tcunderline{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@sethyphenchar
}%
}{}{}%
}
\def\SOUL@tceveryexhyphen#1{%
\SOUL@setkern\SOUL@hyphkern
\SOUL@tcunderline{#1}%
\discretionary{}{}{%
\SOUL@setkern\SOUL@charkern
}%
}
\def\SOUL@tcpostamble{%
\begin{tikzpicture}[decoration={bent,aspect=.3}, overlay]
\draw[decorate,HLcolor,line width=\LineWidth,opacity=\opac] ($(0,-\baseliney+\heighty)$) -- ($(0,-\baseliney)$) ;
\end{tikzpicture}%
}
\def\SOUL@tcsetup{%
\SOUL@setup
\let\SOUL@preamble\SOUL@tcpreamble
\let\SOUL@everysyllable\SOUL@tceverysyllable
\let\SOUL@everyspace\SOUL@tceveryspace
\let\SOUL@everyhyphen\SOUL@tceveryhyphen
\let\SOUL@everyexhyphen\SOUL@tceveryexhyphen
\let\SOUL@postamble\SOUL@tcpostamble
}
\DeclareRobustCommand*\textcirc{\SOUL@tcsetup\SOUL@}
\makeatother
\begin{document}
\vspace*{15cm}
\hbox to 200pt{Lorem ipsum \textcirc{dolor sit} amet}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus
elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur
dictum gravida mauris. \textcirc{Nam arcu libero, nonummy eget,
consectetuer id, vulputate a, magna. Donec vehicula augue eu
neque. Pellentesque habitant morbi tristique senectus et netus et
malesuada fames ac turpis egestas.} Mauris ut leo. Cras viverra
metus rhoncus sem. Nulla et lectus vestibulum urna fringilla
ultrices. Phasellus eu tellus sit amet tortor gravida
placerat. Integer sapien est, iaculis in, pretium quis, viverra ac,
nunc. Praesent eget sem vel leo ultrices bibendum. Aenean
faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac,
nulla. Curabitur auctor semper nulla. \textcirc{Donec varius orci}
eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis,
diam. Duis eget orci sit amet orci dignissim rutrum. Nam dui ligula,
\textcirc{fringilla a, euismod sodales, sollicitudin vel}, wisi. Morbi
auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae,
ultricies et, tellus. \textcirc{Donec aliquet, tortor sed accumsan
bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi.}
Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec
ante. \ul{Pellentesque a nulla.} \textcirc{Cum sociis natoque
penatibus et magnis dis parturient montes, nascetur ridiculus mus.}
Aliquam tincidunt urna. Nulla ullamcorper vestibulum
turpis. Pellentesque cursus luctus mauris.
\end{document}