如何用分层重叠的下划线注释文本

如何用分层重叠的下划线注释文本

下图显示了一些文本,这些文本在下括号中标注了注释“note1”、“note2”和“note3”。如何在 latex 中执行此操作?

在此处输入图片描述

答案1

这是我下面两个解决方案中比较可行的一个,但它使用的是彩色线而不是下括号。它基于我在通过堆叠彩色下划线突出显示文本

\documentclass{article}
\usepackage{stackengine}
\usepackage{xcolor}
\newlength\lunderset
\newlength\rulethick
\lunderset=8.5pt\relax
\rulethick=.8pt\relax
\def\stackalignment{l}
\newcommand\nunderline[3][1]{\setbox0=\hbox{#2}%
  \stackunder[#1\lunderset-\rulethick]{\strut#2}{\color{#3}\rule{\wd0}{\rulethick}}}
\newcommand\nundertext[2][1]{\def\useanchorwidth{T}\def\stackalignment{c}\smash{%
  \stackunder[#1\lunderset-\rulethick+.6\lunderset]{}{%
  \scriptsize\strut#2}}}
\begin{document}
\nunderline{This i\nundertext{Note 3}s }{red}%
\nunderline{\nunderline{some}{red}}{blue}%
\nunderline[2]{ text th\nundertext[2]{Note 2}at I am }{blue}%
\nunderline{\nunderline[2]{writin\nundertext[3]{Note 1}g}{blue}}{cyan}%
\nunderline[3]{ now.}{cyan}
\end{document}

在此处输入图片描述

这种方法可能更容易执行,也可能不容易执行。它基于我在如何在数学模式中链接两个术语收集下部支架

\documentclass{article}
\usepackage{stackengine}
\def\textscrm#1{\textrm{\scriptsize#1}}
\stackMath
\def\rldp{1.3ex}
\def\rlht{.8ex}
\def\rlwd{.8pt}
\setstackgap{L}{\rldp}
\def\uvbarR#1{%
  \def\stackalignment{r}\def\stacktype{S}\stackunder[-\rlwd]{%
    \def\stackalignment{c}\def\stacktype{L}\stackunder{#1}{\rule{\rlwd}{\rlht}}%
  }{\setbox0\hbox{$#1$}\rule{.5\wd0}{\rlwd}}%
}
\def\uvbarL#1{%
  \def\stackalignment{l}\def\stacktype{S}\stackunder[-\rlwd]{%
    \def\stackalignment{c}\def\stacktype{L}\stackunder{#1}{\rule{\rlwd}{\rlht}}%
  }{\setbox0\hbox{$#1$}\rule{.5\wd0}{\rlwd}}%
}
\def\uvbar#1#2{%
  \def\stacktype{S}\def\stackalignment{c}\def\useanchorwidth{T}\stackunder[0pt]{%
    \def\stacktype{L}\setbox0\hbox{${}#1{}$}%
    \stackunder[\rldp]{{}#1{}}{\rule{\wd0}{\rlwd}}%
  }{\def\stacktype{S}\stackunder[1pt]{\rule{\rlwd}{\rlht}}{\scriptstyle#2}}%
}
\newcommand\ubar[2]{\uvbarR{\textrm{}}\uvbar{\textrm{#1}}{\textscrm{#2}}%
  \uvbarL{\textrm{}}}
\newcommand\phubar[2]{\uvbarR{\textrm{}}\uvbar{\phantom{\textrm{#1}}}{\textscrm{#2}}%
  \uvbarL{\textrm{}}}
\begin{document}
\par\ubar{This is some}{Note 3} text that I am writing now.
\par\vspace{-.6\baselineskip}\leavevmode%
\phantom{This is }\phubar{some text that I am writing}{Note 2}%
  \phantom{ now.}
\par\vspace{-.6\baselineskip}\leavevmode%
\phantom{This is some text that I am }\phubar{writing now}{Note 1}%
  \phantom{.}
\end{document}

在此处输入图片描述

答案2

当我们创建宏时,用户的舒适度可能也很重要。因此,我的宏定义了\unotedef“下划线注释”参数的声明位置,然后\unote在实际文本中使用声明的数据。

\def\unotecs#1{\csname unote:#1\endcsname}
\def\unote#1{\leavevmode\hbox to0pt{\vtop{\null \kern-2.5ex \kern\unotecs{#1A}%
   \hbox{$\underbrace{\hskip\unotecs{#1B}}_{\hbox{\unotecs{#1C}}}$}}\hss}}
\def\unotedef#1#2#3#4{%
   \expandafter\def\csname unote:#1A\endcsname{#4}%
   \setbox0=\hbox{#2}\expandafter\edef\csname unote:#1B\endcsname{\the\wd0}%
   \expandafter\def\csname unote:#1C\endcsname{#3}%
}
\unotedef{1} {This is some}{note 3}{0ex}
\unotedef{2} {some text that I am writing}{note 2}{4ex}
\unotedef{3} {writing now}{note 3}{6ex}

\unote{1}This is \unote{2}some text that I am \unote{3}writing now.

乌诺特

相关内容