如何对页边距中的单词进行提示?

如何对页边距中的单词进行提示?

假设我有一些 Latex 文档。我想要做的是,有一种自动突出显示文本中单词的方法,并在同一行的边距中设置一个框,其中包含有关突出显示单词的一些提示。以下是一个例子:

在此处输入图片描述

对于上述文档,我希望自动化工作的方式是:

\makemargintip{form}{this is a word} loops that move water first away...

提示将自动创建在同一行的边距中(或者,如果提示太长,则创建在同一行和后续行的边距中)。请注意,与 不同marginnote,我希望有一个框或其他一些样式元素来界定提示。

感谢您的帮助!

答案1

\marginparxcolor\fbox

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{xcolor}
\newcommand\makemargintip[2]{\textcolor{red}{\fbox{\color{black}#1}}%
  \marginpar{\textcolor{red}{\raisebox{7pt}{%
  \fbox{\parbox[t]{\marginparwidth}{\color{black}#2}}}}}}
\begin{document}
\lipsum[1]
\makemargintip{form}{this is a word} loops that move water first away...
\lipsum[2]
\makemargintip{form}{this is a word that goes on} loops that move water first away...
\lipsum[3]
\end{document}

在此处输入图片描述

如果您想要一个到达纸张边缘的,我只需将其更改\marginparwidth为一些合适的值,在本例中为 1.64 英寸。

此外,如果希望文中的单词带下划线而不是方框,只需将\fbox定义第一行中的更改\makemargintip\underline

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{xcolor}
\newcommand\makemargintip[2]{\textcolor{red}{\underline{\color{black}#1}}%
  \marginpar{\textcolor{red}{\raisebox{7pt}{%
  \fbox{\parbox[t]{1.64in}{\color{black}#2}}}}}}
\begin{document}
\lipsum[1]
\makemargintip{form}{this is a word} loops that move water first away...
\lipsum[2]
\makemargintip{form}{this is a word that goes on and on} loops that move water first away...
\lipsum[3]
\end{document}

在此处输入图片描述

在回答 OP 关于该方法不适用于偶数页的问题时,我可以推测问题与我的第二种方法有关,即在使用边距不对称的文档类时,每一页的不对称都会翻转。

这是一种半自动处理的方法,除非提示出现在前一页的延续段落中如果需要人工干预,则应[r]在偶数页上提供可选参数([l]对于奇数页):

\documentclass{book}
\usepackage[nopar]{lipsum}
\usepackage{xcolor,everypage}
\def\pagesense{o}
\AddEverypageHook{\if o\pagesense\gdef\pagesense{e}\else\gdef\pagesense{o}\fi}
\newcommand\makemargintip[3][x]{%
  \textcolor{red}{\underline{\color{black}#2}}%
  \ifx x#1%
    \if o\pagesense\def\tmp{l}\else\def\tmp{r}\fi%
    \marginpar{\makebox[\marginparwidth][\tmp]{\textcolor{red}{\raisebox{7pt}{%
    \fbox{\hspace{20pt}\parbox[t]{1.64in}{\color{black}#3}\hspace{20pt}}}}}}%
  \else%
    \marginpar{\makebox[\marginparwidth][#1]{\textcolor{red}{\raisebox{7pt}{%
    \fbox{\hspace{20pt}\parbox[t]{1.64in}{\color{black}#3}\hspace{20pt}}}}}}%
  \fi%
}
\begin{document}
\lipsum[1]
\makemargintip{form}{this is a word} loops that move water first away...
\lipsum[2]
\makemargintip{form}{this is a word that goes on and on} loops that move water first away...
\lipsum[3-7]
\makemargintip[r]{form}{for carry over paragraph on a page, manual intervention
  is needed, because it is actually ``set'' on the prior page} loops that move water first away...
  \lipsum[8]

But after \makemargintip{that}{but not after that}, no optional argument is needed.
\end{document}

在此处输入图片描述

在此处输入图片描述

答案2

todonotes包使用与上一个答案中所示的相同的宏,但我相信它更容易操作。这是我的建议

\documentclass{article}
\usepackage{todonotes}
\usepackage{xcolor}
\usepackage{lipsum}

\newcommand{\tipword}[1]{\colorlet{currentcolor}{.}{\color{red}\fbox{\color{currentcolor}#1}}}
\newcommand{\tipitself}[1]{\todo[backgroundcolor=white,bordercolor=red,fancyline]{#1}}
\newcommand{\makemargintip}[2]{\tipword{#1}\tipitself{#2}}

\begin{document}
    \lipsum[1-2]


    Now this is where the tip word comes in, it's \makemargintip{form}{this is the tip} can be shaped with the todo package

    \lipsum[3-4]
\end{document}

在此处输入图片描述

相关内容