Índice de contenidos y referencias cruzadas en varios capítulos.

Índice de contenidos y referencias cruzadas en varios capítulos.

Esta es una continuación de la pregunta.Referencias cruzadas en varios capítulos. Siguiendo la respuesta a esta pregunta, estoy usando las siguientes macros:

\newcommand*\maybechapter[1]{%   
 % Tests if current chapter is equal to the chapter number of label)
 \ifnum\value{chapter}=0#1\relax
     % Print nothing if so
 \else
     % Set 'chapter' locally (=> no \setcounter) to the label chapter and
     % print it in the usual format followed by a dot
     {\value{chapter}=#1\relax\thechapter.}%
 \fi
}
\renewcommand*\thesection{%
    \protect\maybechapter{\arabic{chapter}}\arabic{section}%
}

Esto funciona como se esperaba para las referencias, pero en la tabla de contenido, los números de sección ahora están precedidos por los números de capítulo:

I The first chapter
    I.1 The first section of the first chapter

pero me gustaría conseguir algo como

I The first chapter
    1 The first section of the first chapter

¿Cómo debo modificar \maybechapter para obtener este resultado?

Respuesta1

Modificaría la respuesta allí en un par de puntos:

\documentclass{book}

\renewcommand*\thechapter{\Roman{chapter}}

\renewcommand*\thesection{%
    \maybechapter{\arabic{chapter}}\arabic{section}%
}

% Maybe print the chapter number
\protected\def\maybechapter#1{%
   % Tests if current chapter is equal to the chapter number of label)
   \ifnum\value{chapter}=0#1
   \else
     \uppercase\expandafter{\romannumeral#1}.%
   \fi
}

% Test document:
\begin{document}

\begingroup
\def\maybechapter#1{}
\tableofcontents
\endgroup

\chapter{One}

\section{S1}\label{S1}

Here's a reference to Section~\ref{S1},
one to Section~\ref{S2}, and one to
Section~\ref{S3}.

\section{S2}\label{S2}

Text

\chapter{Two}

\section{S3}\label{S3}

\end{document}

El uso \protected\defde asegura \maybechapternunca se expande en una operación de escritura; ya que las entradas para el TOC se sometendosoperaciones de escritura, una \protectno es suficiente.

Para el TOC, desactivo localmente el \maybechaptercomando, para que devore su argumento.

ingrese la descripción de la imagen aquí

información relacionada