修改复杂参数第一个字符上的 \overline

修改复杂参数第一个字符上的 \overline

我一直在使用zref来处理我的引用。它允许我通过其属性列表以我想要的方式自定义引用。特别是,我引用了文档中以自动方式创建的各种结构。以下是提供设置并说明我当前问题的 MWE:

\documentclass{article}
\usepackage{zref}% http://ctan.org/pkg/zref
\makeatletter
\newcounter{thegraph}% Graph counter
\zref@newlist{graph}% Graph reference stored in list 'graph'
\zref@newprop*{type}[??]{??}% Create new 'graph type' property
\zref@newprop*{number}[??]{\thethegraph}% Create new 'graph number' property
\zref@addprops{graph}{type, number}% Graph reference (or property list) has type & number
\newcommand{\graph}[1]{\zref@setcurrent{type}{G}\newgraph{1}{#1}}%
\newcommand{\digraph}[1]{\zref@setcurrent{type}{D}\newgraph{2}{#1}}%
\newcommand{\newgraph}[2]{% New graph #1=type; #2=ref
  \refstepcounter{thegraph}% Increase counter
  % zref label has to written immediately (not at page shipout), since more than one new graph may appear on page
  \zref@wrapper@immediate{\zref@labelbylist{#2}{graph}}% Write graph list to .aux (using zref)
  \label{#2}% Label newgraph for reference
  \ifnum#1>0\ensuremath{\zref@getcurrent{type}_{\thethegraph}}\fi% Print graph symbol (if requested)
}
\newcommand{\graphref}[1]{\ensuremath{\zref@extract{#1}{type}_{\zref@extract{#1}{number}}}}% Reference to a graph
\newcommand{\complementg@aux}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}
\newcommand{\complementg}[2][3]{\edef\@tempa{#2}\expandafter\complementg@aux\expandafter[\expandafter#1\expandafter]\@tempa}
\makeatother

\begin{document}

This is~\graph{first} and~\digraph{second}. Now see~\graphref{first} and~\graphref{second}.
What about~$\complementg{\graphref{first}}$ and~$\complementg{\graphref{second}}$?

\end{document}

上述 MWE 给出以下输出

在此处输入图片描述

我希望它看起来像这样:

在此处输入图片描述

This is~$G_1$ and~$D_2$. Now see~$G_1$ and~$D_2$.
What about~$\complementg{G_1}$ and~$\complementg{D_2}$?

选择\complementg源于聊天中的讨论并且因为它在非zref实施中发挥了作用。

我的问题是:如何定义\complementg允许在以下所有格式中使用,同时仅为\overline第一个字符提供“修改”:

$\complementg{G_1}$% Basic math content with subscript manual subscript
$\complementg{\graphref{lab}}$% Referenced zref label (like above)
$\complementg{\mathcal{G}}$% "Complex" formatting of content

从印刷意义上讲,这个问题与用单字符下标编写向量的正确方法是什么?

答案1

\ensuremath这是我的“除非真正必要,否则不要使用”活动中的又一颗珍珠。

\documentclass{article}
\usepackage{zref}

\makeatletter
\newcounter{thegraph}% Graph counter
\zref@newlist{graph}% Graph reference stored in list 'graph'
\zref@newprop*{type}[??]{??}% Create new 'graph type' property
\zref@newprop*{number}[??]{\thethegraph}% Create new 'graph number' property
\zref@addprops{graph}{type, number}% Graph reference (or property list) has type & number

\newcommand{\graph}[1]{\zref@setcurrent{type}{G}\newgraph{1}{#1}}%

\newcommand{\digraph}[1]{\zref@setcurrent{type}{D}\newgraph{2}{#1}}%

\newcommand{\newgraph}[2]{% New graph #1=type; #2=ref
  \refstepcounter{thegraph}% Increase counter
  % zref label has to written immediately (not at page shipout),
  % since more than one new graph may appear on page
  \zref@wrapper@immediate{\zref@labelbylist{#2}{graph}}% Write graph list to .aux (using zref)
  \label{#2}% Label newgraph for reference
  % Print graph symbol (if requested)
  \ifnum#1>\z@\ensuremath{\zref@getcurrent{type}_{\thethegraph}}\fi
}
%%% DON'T use \ensuremath here
\newcommand{\graphref}[1]{\zref@extract{#1}{type}_{\zref@extract{#1}{number}}}% Reference to a graph
\newcommand{\complementg@aux}[2][3]{{}\mkern#1mu\overline{\mkern-#1mu#2}}

%%% Less clumsy definition of \complementg    
\newcommand{\complementg}[2][3]{%
  \begingroup\edef\x{\endgroup
  \unexpanded{\complementg@aux[#1]}#2}\x}
\makeatother

\begin{document}

This is~\graph{first} and~\digraph{second}. 
Now see~$\graphref{first}$ and~$\graphref{second}$.
What about~$\complementg{\graphref{first}}$ 
and~$\complementg{\graphref{second}}$?

\end{document}

在此处输入图片描述

相关内容