# What do the packages amsmath and libertine do that prevents counters from working?

So I have been using a custom setup of counters after some great help on here (thank you, egreg).

The thing is, I have been running into a really odd problem with the counters which I am just unable to reproduce and pinpoint in a reliable way. But I finally have found the culprits... I think.

Is there a way I can use libertine and amsmath in a reliable fashion so I do not have this experience? Or did I perhaps mis-configure som

# Picture 1 with counters not working

Compiled with amsmath and libertine loaded so the counters do not work:

# Picture 2 with counters working

Compiled with amsmath and libertine commented out:

# MWE

% !TeX spellcheck = de_DE
\documentclass[
11pt,
a4paper,
DIV=15,
twoside,
parskip=single,
twopage,
]
{scrartcl}

\usepackage[german]{babel}
\usepackage{
multicol,
setspace,
enumitem,
xcntperchap,
}
\usepackage{amsmath}
\usepackage{textcomp}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% the problematic package
\usepackage[oldstyle,proportional]{libertine}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{libertinust1math}
\usepackage[scaled=0.832]{beramono}
\usepackage[scale=0.8558]{tgheros}
\usepackage{microtype}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\pdfgentounicode=1

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%    A4    %%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcounter{TOTALcounter} % for 'total' counters
\newcounter{counterPERsection}[section]
\RegisterTrackCounter{section}{counterPERsection}
\newcounter{questioncounter}
\RegisterTrackCounter{TOTALcounter}{questioncounter}
% initialize the total counters
\stepcounter{TOTALcounter}
\newcommand{\flashc}[2]{%
\noindent\fbox{%
\begin{minipage}[t]{\columnwidth}%
\stepcounter{counterPERsection}%
\arabic{counterPERsection}.%
\ObtainTrackedValueExp{section}{counterPERsection}%
\newline
\stepcounter{questioncounter}\arabic{questioncounter}.%
\ObtainTrackedValueExp{TOTALcounter}{questioncounter}\newline%
{#1}%
\end{minipage}}\\[2pt]
#2\vspace{3pt}}

\newcommand{\personone}{\subsection{Stuff by Person1}}
\newcommand{\stufftwo}{\subsection{Stuff by Person2}}
\newcommand{\stuffthree}{\subsection{Stuff by Person3}}

\listfiles

\begin{document}
\begin{multicols*}{2}
\section{AAAAAAAA}
\personone
\flashc{444444444444}{}

\flashc{444444444444}{}

\stufftwo
\flashc{444444444444}{}
\flashc{gggggggggggggg}{}
\stuffthree
\flashc{gggggggggggggg}{}
\flashc{ggggggg}{}

\section{BBBBB}
\personone
\flashc{gggggggggggggg!}{}
\flashc{gggggggggggggg}{}
\stufftwo

\flashc{444444444444}{}
\flashc{ggggggg}{}
\flashc{gggggggggggggg}{}
\end{multicols*}
\end{document}


# Log

https://pastebin.com/V4yCDGtz

• libertine is not involved. Load amsmath before xcntperchap and hope that this doesn't break the amsmath usage of the counters. – Ulrike Fischer Jun 13 '20 at 16:18
• @UlrikeFischer Could you please provide your comment as a reply so I could mark the thread/problem as solved? (And yes, I do really hope and pray that this issue won't pop up again!). – henry Jun 13 '20 at 16:30
• If you compile this on XeLaTeX or LuaLaTeX, libertine will load fontspec and prevent either tgheros or beramono from working. You can fix this either by loading those in fontspec as well (\defaultfontfeatures{Scale = MatchLowercase} \setsansfont{TeX Gyre Heros} \setmonofont{DejaVu Sans Mono}) or by adding the type1 option to libertine. – Davislor Jun 13 '20 at 20:46
• Unrelated to your problem, as Ulrike Fischer said, but something to be aware of. – Davislor Jun 13 '20 at 20:54
• @Davislor ... well ok, thanks, but this is clearly outside of the scope of this thread. – henry Jun 15 '20 at 7:57

amsmath (or more precisely amstext) redefines \stepcounter and so overwrites the changes from xcntperchap. If you load amsmath before xcntperchap it will probably work (if the additions of xcntperchap` don't confuse amsmath somewhere.