2

For a conference paper I have to use a custom package provided by the conference. This package contains the following line:

\renewcommand{\thesection}{\arabic{section}.}

which puts a dot after the number in a section title. Now, when I add a reference to a section, the dot is shown in the reference as well. MWE:

\documentclass{article}
% real code:
% \usepackage{myconference}
% MWE code:
\renewcommand{\thesection}{\arabic{section}.}
\begin{document}

\section{First section}
\label{sec:first}
In Section~\ref{sec:first} the reference does not look good.
\end{document}

enter image description here

The style guide of the conference does not specify the appearance of section references. Therefore, I would like to remove the dot in the reference (while keeping the dot in the title itself). I am not allowed to change the conference package, but I can modify the code of my own paper, including redefining \ref (or using a custom command for referencing) if necessary. Any ideas?

6
  • Instead of trying to remove it from the reference, you should not put it there in the first place. Perhaps follow the instructions in How to add a dot after the section number?
    – Werner
    Feb 5, 2018 at 16:11
  • @Marijn Look at the egreg ansver tex.stackexchange.com/a/24444/66024 Feb 5, 2018 at 16:17
  • @Werner you are right, of course, but this is what the conference provides (which I cannot change).
    – Marijn
    Feb 5, 2018 at 16:20
  • 1
    @Marijn: That's fine... since you're defining your own content anyway, you can redefine it back to what it was (\renewcommand{\thesection}{\arabic{section}}) and then use other packages or a manual correct of \@seccntformat.
    – Werner
    Feb 5, 2018 at 16:27
  • 1
    @Werner that is a good idea as well! I think I prefer the black magic of Christian Hupfer though.
    – Marijn
    Feb 5, 2018 at 16:32

1 Answer 1

1

One could gobble the . by using something like \def\@gobbledot, delimiting it with \csname thesection\endcsname and then redefine \p@section, which is basically responsible for the cross-reference formatting.

The approach is quite similar to my answer to Automatically encase a cross-referenced equation number in round parentheses or to Reference appendix objects within texts as 'A. 1', but not 'Appendix A. 1'

\documentclass{article}
% real code:
% \usepackage{myconference}
% MWE code:

\renewcommand{\thesection}{\arabic{section}.}

\makeatletter
\def\@gobbledot\csname thesection\endcsname{\arabic{section}}
\renewcommand{\p@section}{\@gobbledot}
\makeatother
\begin{document}

\section{First section}
\label{sec:first}
In Section~\ref{sec:first} the reference does not look good.
\end{document}
2
  • This works perfectly, I didn't know LaTeX can gobble so many things :)
    – Marijn
    Feb 5, 2018 at 16:23
  • @Marijn: Well, using a \def and 'entities' other than {} as delimiters is Black Magic, of course ;-). Please note that you have to do the same trick for \p@subsection etc. as well if needed, but with another definition of say \@gobblesubsecdot etc.
    – user31729
    Feb 5, 2018 at 16:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .