
當重新定義部分等時,參考中的編號不再正確。
我的 MWE 是:
\documentclass[twoside]{book}
% possibility to have sections etc. be within the margins
\makeatletter
\newcommand{\doxysection}{\@ifstar{\doxysection@star}{\doxysection@nostar}}
\newcommand{\doxysection@star}[1]{\begingroup\sloppy\raggedright\section*{#1}\endgroup}
\newcommand{\doxysection@nostar}[1]{\begingroup\sloppy\raggedright\section{#1}\endgroup}
\makeatother
\usepackage[pdftex,pagebackref=true]{hyperref}
\hypersetup{ colorlinks=true, linkcolor=blue, citecolor=blue, unicode }
\begin{document}
\chapter{Special Commands}
\doxysection{Introduction}
\begin{list}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdaddtogroup}{addtogroup}}}{\ref{commands_cmdaddtogroup}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdcallgraph}{callgraph}}}{\ref{commands_cmdcallgraph}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdhidecallgraph}{hidecallgraph}}}{\ref{commands_cmdhidecallgraph}}{}
\end{list}
\hypertarget{commands_cmdaddtogroup}{}\doxysection{addtogroup}\label{commands_cmdaddtogroup}
\hypertarget{commands_cmdcallgraph}{}\section{callgraph}\label{commands_cmdcallgraph}
\hypertarget{commands_cmdhidecallgraph}{}\doxysection{hidecallgraph}\label{commands_cmdhidecallgraph}
\end{document}
我得到的輸出是:
出於本範例的目的,我在第一節的節定義中使用了重新定義的節,對於節節使用了原始節,對於第三節再次使用了重新定義的節。
在這裡我們看到第一個參考文獻引用了第 1 節,儘管這應該是 1.2。第二個參考是正確的,但第三個參考又是錯誤的,這應該是 1.4 而不是 1.3
看起來透過重新定義該部分,「編號」不會在新命令中匯入/更新。
(tex 代碼摘錄自 doxygen 通常自動產生的代碼。)
我要怎麼解決這個問題?
答案1
您正在對部分標題進行分組,這會破壞 \label 系統,因為標籤名稱儲存在本機。
更好地使用以下命令正確定義您自己的切片命令\@startsection
:
\documentclass[twoside]{book}
% possibility to have sections etc. be within the margins
\makeatletter
\newcommand\doxysection{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\raggedright\normalfont\Large\bfseries}}
\makeatother
\usepackage[pagebackref=true]{hyperref}
\hypersetup{ colorlinks=true, linkcolor=blue, citecolor=blue, unicode }
\usepackage{lipsum}
\begin{document}
\chapter{Special Commands}
\doxysection{Introduction}
\begin{list}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdaddtogroup}{addtogroup}}}{\ref{commands_cmdaddtogroup}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdcallgraph}{callgraph}}}{\ref{commands_cmdcallgraph}}{}
\item \contentsline{section}{\mbox{\hyperlink{commands_cmdhidecallgraph}{hidecallgraph}}}{\ref{commands_cmdhidecallgraph}}{}
\end{list}
\hypertarget{commands_cmdaddtogroup}{}\doxysection{addtogroup}\label{commands_cmdaddtogroup}
\hypertarget{commands_cmdcallgraph}{}\section{section}\label{commands_cmdcallgraph}
\hypertarget{commands_cmdhidecallgraph}{}\doxysection{hidecallgraph}\label{commands_cmdhidecallgraph}
\end{document}