\point
我有一个使用该包添加$\bigstar$
作为边注的命令。但如果每行marginnote
有多个星号,我希望多个星号彼此相邻。因此在边注中生成两个。目前,两个星号都生成了,但我认为它们相互重叠,看起来只有一个。\point
Hello \point\point world.
$\bigstar$
我的想法是使用一个计数器,该计数器在每个换行符时重置。但这可能吗?我找到了使用 执行段落开头命令的命令\everypar
。是否有命令可以向文档的每个生成的输出行添加一些内容?
答案1
这里有一个替代建议,即添加一个测试\marginnote
,如果最后一个\marginnote
具有相同的垂直位置,则将输出向右移动 a 的宽度\bigstar
:
\documentclass{article}
\usepackage{amssymb}
\usepackage{marginnote}
\usepackage{xpatch}
\makeatletter
\newcommand*\@mn@lastypos{\relax}
\newcommand*\@mn@lastpage{\relax}
\newlength{\@mn@currmove}
\setlength{\@mn@currmove}{\z@}
\providecommand\@firstofthree[3]{#1}
\providecommand\@secondofthree[3]{#2}
%\providecommand\@thirdofthree[3]{#3}% Already defined in LaTeX from 1998/03/20
\@ifundefined{pdflastypos}{%
\let\mn@lastypos\lastypos
}{%
\let\mn@lastypos\pdflastypos
}
\xpatchcmd{\@mn@margintest}{%
\protected@write\@auxout{\let\themn@abspage\relax}{%
\string\newmarginnote{note.\@mn@thispage.\@mn@atthispage}{%
{\themn@abspage}{\noexpand\number\mn@lastxpos sp}}%
}%
}{% extend \newmarginnote by the y pos
\protected@write\@auxout{\let\themn@abspage\relax}{%
\string\newmarginnote{note.\@mn@thispage.\@mn@atthispage}{%
{\themn@abspage}{\noexpand\number\mn@lastxpos sp}{\noexpand\number\mn@lastypos}}%
}%
}{}{\undefined}
\xpatchcmd{\@mn@margintest}{%
\edef\@mn@currxpos{\expandafter\@secondoftwo\@mn@currpage}%
}{% the x pos is now the second of three arguments and the third is the y pos
\edef\@mn@currxpos{\expandafter\@secondofthree\@mn@currpage}%
\edef\@mn@currypos{\expandafter\@thirdofthree\@mn@currpage}%
}{}{\undefined}
\xpatchcmd{\@mn@margintest}{%
\edef\@mn@currpage{\expandafter\@firstoftwo\@mn@currpage}%
}{% the page number is now the first of three arguments
\edef\@mn@currpage{\expandafter\@firstofthree\@mn@currpage}%
}{}{\undefined}
\xapptocmd{\@mn@margintest}{% now add the y pos testing and the offset
\settowidth\@tempdima{\ensuremath{\bigstar}}%
\ifx\@mn@lastpage\@mn@currpage
\ifx\@mn@lastypos\@mn@currypos
\global\advance\@mn@currmove\@tempdima
\else
\global\@mn@currmove\z@
\fi
\else
\global\@mn@currmove\z@
\fi
\@ifundefined{@mn@currxpos}{}{%
\edef\@mn@currxpos{\the\dimexpr \@mn@currxpos-\@mn@currmove\relax}%
}%
\global\let\@mn@lastpage\@mn@currpage
\global\let\@mn@lastypos\@mn@currypos
}{}{\undefined}
\makeatother
\newcommand*{\point}{\marginnote{\ensuremath{\bigstar}}}
\begin{document}
Test\point
Test\point Test\point
Test\point Test\point Test\point
Test\point
\end{document}