1

[First edit, with many changes] I wanted to remove the numbering of the sections so I copied the following from this answer by user zwol:

\renewcommand{\thesection}{}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\csname #1ignore\expandafter\endcsname\csname the#1\endcsname\quad}
\let\sectionignore\@gobbletwo
\let\latex@numberline\numberline
\def\numberline#1{\if\relax#1\relax\else\latex@numberline{#1}\fi}
\makeatother

We'll call the code above "zwol code".

I have two tex files that have the same code but where the zwol code is in different positions. We'll call "code B" to the code that has the zwol code before calling the packages. This is code B:

\documentclass[11pt, fleqn]{article}

\renewcommand{\thesection}{}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\csname #1ignore\expandafter\endcsname\csname the#1\endcsname\quad}
\let\sectionignore\@gobbletwo
\let\latex@numberline\numberline
\def\numberline#1{\if\relax#1\relax\else\latex@numberline{#1}\fi}
\makeatother

\usepackage[vcentering]{geometry}
\geometry{papersize={3.25in,15.5in},total={3in,15in}}

\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}

\begin{document}

\title{something}
\date{}
\maketitle

\section{mysection} % (fold)
\label{sec1}
lorem ipsum
\\

\end{document}

This is what I get after compiling code B with pdflatex:

Code B with pdflatex

And this is "code A", the code that has the zwol code after calling the packages:

\documentclass[11pt, fleqn]{article}

\usepackage[vcentering]{geometry}
\geometry{papersize={3.25in,15.5in},total={3in,15in}}

\usepackage[spanish]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}

\renewcommand{\thesection}{}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}
\makeatletter
\def\@seccntformat#1{\csname #1ignore\expandafter\endcsname\csname the#1\endcsname\quad}
\let\sectionignore\@gobbletwo
\let\latex@numberline\numberline
\def\numberline#1{\if\relax#1\relax\else\latex@numberline{#1}\fi}
\makeatother

\begin{document}

\title{something}
\date{}
\maketitle

\section{mysection} % (fold)
\label{sec1}
lorem ipsum
\\

\end{document}

After compiling with pdflatex:

Code A with pdflatex

When I compile code B with pdflatex, the pdf showed dots before the section titles: ". mysection". However, with code A, the pdf appeared as I wanted it, showing the sections titles without any dot before them: "mysection" .

Why did this happen?

  • I get no period. Actually I had to remove the two \addtolength commands in order to see a section title. – egreg Apr 10 '18 at 21:06
  • 3
    Quite odd paper layout settings. For example, paper height equals text height, but then the text height is further increased. A part of the text height is now outside of the paper. Second example, the width is already very, very small, but package multicol is added with a quite large \columnsep. This gives very narrow columns. – Heiko Oberdiek Apr 10 '18 at 21:08
  • 1
    are you really using latex+dvips, not pdflatex? – David Carlisle Apr 10 '18 at 21:17
  • @HeikoOberdiek I was actually not sure of the meaning of all the commands I was using. Thank you for pointing that out, your explanation has given me some clues of what some of the commands actually mean. I will check my code again and add an edit if necessary. DavidCarlisle, I am using pdflatex with texlive on a MacBook with macOS Sierra – evaristegd Apr 10 '18 at 21:46
  • @DavidCarlisle I just realized my code says dvips on the line with the geometry package. Most probably I just copy-pasted that from somewhere. Do you think that line of code may be related to the problem? Keep in mind that I was compiling my tex file with pdflatex on a MacBook's Terminal – evaristegd Apr 10 '18 at 21:58
2

Whether you put \renewcommand before or after package loading is the same issue as whether two packages should be loaded in one order or the other. If they define different commands it makes no difference but if they define the same command then, depending on the definition forms used, it could be an error, or the first or second definition could "win".

In this case, if you modify the input to look like

\show\@seccntformat
\usepackage[spanish]{babel}
\show\@seccntformat

You will see on the terminal and log file

> \@seccntformat=macro:
#1->\csname #1ignore\expandafter \endcsname \csname the#1\endcsname \quad .
l.16 \show\@seccntformat

? 
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/babel.sty
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/switch.def)
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel-spanish/spanish.ldf
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/babel.def
(/usr/local/texlive/2018/texmf-dist/tex/generic/babel/txtbabel.def))))
> \@seccntformat=macro:
#1->\csname the#1\endcsname .\quad .
l.18 \show\@seccntformat

? 

so the babel spanish option defines this command to have a . and 1em space.

So in the first version your definition of \@seccntformat is not used as babel has redefined it before you use it. In your second version, then first babel redefines it, but then you over-write that definition so your definition "wins".

  • Exactly the answer I was looking for, thank you! – evaristegd Apr 10 '18 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.