|
在写较长论文或写书的时候,交叉引用会很多,通常较前写的 label 到后面就不记得了,需要翻查。
还好 PDF 与 tex 有双向搜索,从 PDF 双击跳到 tex 找到 label,复制,返回到正在写的地方粘贴,不算麻烦,但也有丁点儿麻烦,一直以来也就这样了。
今天无意中在某模板里看到一种处理方式,那就是新建一个命令,其定义是 label 后把名称也输出,在完稿后再改成仅 label。
这样在 PDF 就可以直接复制 label,不用在 tex 里跳来跳去,确实省事了些。
想法是好,不过该模板所给的定义却很粗糙:- \newcommand{\mlabel}[1]{\label{#1} % Use the next two lines to show names
- {\hfill \hspace{1cm}{\small\tt{{\ }\hfill(#1)}}}}
复制代码 实际使用时往往影响原内容的排版,特别是在公式中,因为这时 \hfill 没用,同时也占了公式的位置,很难看。
当然这些其实都无所谓,反正只是暂时的,完稿后就没用了,但我还是觉得有必要改进一下,毕竟写的时候太难看也会影响心情。
为了尽量不影响原内容的排版,显示的 label 名应该放到边注中去,但在公式中用 latex 自带的 \marginpar 似乎有问题,所以这里使用一个专门处理边注的宏包 marginnote。
测试代码:- \documentclass{article}
- \usepackage{amsmath,amsthm,xcolor}
- \newif\ifshowlables
- \showlablestrue
- \ifshowlables
- \usepackage{marginnote}
- \newcommand\mlabel[1]{\label{#1}%
- \marginnote{\normalfont\small\texttt{\color{blue}#1}}}%
- \else\let\mlabel\label\fi
- \usepackage{hyperref}
- \newtheorem{thm}{theorem}
- \begin{document}
- \section{test}\mlabel{sec:01}
- some text
- \begin{thm}\mlabel{thm:AG}
- the AG inequality is:
- \begin{equation}\mlabel{eqn:AG}
- a+b\ge2\sqrt{ab}.
- \end{equation}
- \end{thm}
- ying yong: Section \ref {sec:01}, Theorem \ref {thm:AG} and Equation \ref {eqn:AG}.
- \end{document}
复制代码 效果:
完稿后,将上述代码的第四行注释掉,然后删除 .aux 文件再编译即可。 |
|