0

I created new align-environments that places a "I." (or "II.") in front of the number of the equation (for example, I want to use I.1, I.2, etc. in the first part of my document and II.1, II.2, etc. in the second). However, the hyperrefs don't work correctly. If I click on a reference to II.2, for example, I end up at I.1.

In a simplified example, it works:

    \documentclass[
12pt,
a4paper,
titlepage]{article}

\usepackage{amsmath}
\usepackage{hyperref}
%*********************************************************
%****Define new align-environments
%*********************************************************
% I.
\newcommand{\thealignedIal}{I.\arabic{equation}}

\makeatletter
\newenvironment{romanalignI}{%
    \let\theequation\thealignedIal
    }{}
\makeatother

%% II.
\newcommand{\thealignedIIal}{II.\arabic{equation}}
\makeatletter
\newenvironment{romanalignII}{%
    \let\theequation\thealignedIIal
    }{}
\makeatother

\begin{document}

This is part I of my document, so I would like to use \textit{romanalignI}: 
\begin{romanalignI}
\begin{align}
1+1 = 2 \label{eq1}
\end{align}
\end{romanalignI}

Now a second equation: 
\begin{romanalignI}
\begin{align}
2+2 = 4 \label{eq2}
\end{align}
\end{romanalignI}

It works fine when referencing them: \eqref{eq1} and \eqref{eq2}. \\

\newpage

Now, let's move on to part II and use \textit{romanalignI}: 
\begin{romanalignII}
\begin{align}
1+1 = 2 \label{eq3}
\end{align}
\end{romanalignII}

Now a second equation: 
\begin{romanalignII}
\begin{align}
2+2 = 4 \label{eq4}
\end{align}
\end{romanalignII}

Again, the referencing works fine: \eqref{eq3} and \eqref{eq4}.
\end{document}

But in the "real" document it stopps working properly:

Master Document

\documentclass[
12pt,
titlepage]{article}

% Space before/after align
\setlength{\abovedisplayskip}{0pt}
\setlength{\belowdisplayskip}{0pt}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayshortskip}{0pt}

\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[normalem]{ulem} % strike through text
\usepackage{scrextend}

\usepackage{color}
\usepackage{xcolor} 
\definecolor{primary}{HTML}{08457E}
\usepackage{colortbl}
\usepackage{graphicx}
\usepackage{amsmath, bm}
\usepackage{physics} % for partial derivatives with \pdv
\usepackage{microtype} % für die Mikrotypografie (besseres Schriftbild)
\usepackage{lscape} %singles pages as landscape
\usepackage{rotating} % for 'sidewaystable' environment
\usepackage{tikz} %econ drawing
\usepackage{ragged2e}
\usepackage{subfig} %tables next to each other

% allow for different spacing options 
\usepackage{setspace} 
\doublespacing

% allow for different spacing options in enumerate/itemize
\usepackage{enumitem}

%Formatierung Bilder
\usepackage{caption}
\DeclareCaptionLabelSeparator{just_a_colon}{: }
\captionsetup[figure]{
    position=below,
    labelsep=just_a_colon
}
\makeatletter
\renewcommand*\l@figure{\@dottedtocline{1}{0em}{1em}}
\makeatother

%Hyperlinks 
\usepackage{hyperref}
% colored links
\hypersetup{
    colorlinks=true,%set true if you want colored links
    linktoc=all,
    %set to all if you want both sections and subsections        linked
    filecolor=black,
    citecolor={blue!40!black},
    linkcolor={blue!40!black},
    urlcolor=black,
    %linktocpage, 
    %only link the page numbers and not the entire table    of contents
}

% For Tables
\usepackage[labelfont=bf]{caption}
\captionsetup[table]{labelsep=space, 
         justification=raggedright, singlelinecheck=off}
\usepackage{caption,threeparttable}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{adjustbox}
\usepackage{array} %center with m{} 
%-> ">{\centering\arraybackslash}p{0.3\linewidth} | >{\centering\arraybackslash}p{0.3\linewidth}"
\usepackage{tablefootnote}

% Appendix
\usepackage[title]{appendix}

%Gliederungsebenen
\setcounter{tocdepth}{4}
\setcounter{secnumdepth}{4}


\usepackage[bottom, hang, flushmargin]{footmisc} % put footnote as much to the bottom as possible AND no indent

% no indentation of new lines
\usepackage[parfill]{parskip}
\setlength{\parindent}{0pt}

% set font to Times New Roman
\usepackage{times}

% add table of figures/tables to table of contents
\usepackage[nottoc]{tocbibind} 

% widow / orphan control
\usepackage[all]{nowidow}


\usepackage[
  a4paper,
  left=20mm,
  right=20mm,
  top=10mm,
  bottom=30mm,
  scale=1 %,
  %showframe
  ]{geometry}       % Seitenränder und Bindungskorrektur einstellen
  
\setlength{\headsep}{0.3in} % add space between header and text

%*********************************************************
%****CUSTOM COMMANDS
%*********************************************************
\newcommand{\submissiondate}{INSERT SUBMISSION DATE}
% Define checkmark
\usepackage{pifont}
\newcommand{\checkmark}{\ding{51}}
\newcommand{\xmark}{\ding{55}}

\usepackage{accents}
\newcommand{\ubar}[1]{\underaccent{\bar}{#1}}


%*********************************************************
%****Define new align-environments
%*********************************************************
% Römisch Erstens
\newcommand{\thealignedIal}{I.\arabic{equation}}

\makeatletter
\newenvironment{romanalignI}{%
    \let\theequation\thealignedIal
    }{}
\makeatother

%% Römisch Zweitens
\newcommand{\thealignedIIal}{II.\arabic{equation}}
\makeatletter
\newenvironment{romanalignII}{%
    \let\theequation\thealignedIIal
    }{}
\makeatother
%*********************************************************
%****Formatierung des Titelblatts
%*********************************************************
\title{%
  This is the title}
\newcommand*\mytitle{}
\makeatletter
\let\mytitle\@title
\makeatother

%\linespread{1.5}
\pagestyle{myheadings}

\setlength{\headheight}{1.8\baselineskip}
\usepackage{scrlayer-scrpage}
\pagestyle{scrheadings}
\clearscrheadfoot

% Colorboxes
\usepackage{tcolorbox}
\newtcolorbox{mybox}[3][]
{
  colframe = #2!25,
  colback  = #2!10,
  coltitle = #2!20!black,  
  title    = {#3},
  #1,
}

%*********************************************************
%****BEGIN DOCUMENT
%*********************************************************
\begin{document}

%*********************************************************
%****GENERATE TITLEPAGE
%*********************************************************
\begin{titlepage}
\begin{center}

\vspace*{0.5cm}

{\bfseries\Large\textsc{\mytitle}}\\

\vspace*{2.5cm}


{more text}\\

\vspace{1cm}

Name of Institution  \\

\vspace{2cm}

City, \submissiondate
\end{center}
\end{titlepage}

\newgeometry{
  left=33mm,
  right=23mm,
  top=23mm,
  bottom=23mm,
  scale=1}  

%*********************************************************
%****ABSTRACT
%*********************************************************
\vspace*{2cm}
\section*{\centering{Abstract}} \label{Abstract}
%\begin{center}
\begin{addmargin}[10pt]{10pt}
\input{./Kapitel/Abstract}
\end{addmargin}
%\end{center}
\newpage
%*********************************************************
%****GENERATE TABLE OF CONTENTS
%*********************************************************
\thispagestyle{empty} %no header/footer
{
\onehalfspacing
  \hypersetup{linkcolor=black}
  \tableofcontents
  \makeatletter
  \renewcommand*{\ext@figure}{lot}
  \let\c@figure\c@table
  \let\ftype@figure\ftype@table
  \let\listoftableandfigures\listoftables
  \renewcommand*\listtablename{List of Tables and figures}
  \makeatother
}

%*********************************************************
%****List of Figures / Tables
%*********************************************************
{
  \hypersetup{linkcolor=black}
  \listoffigures
  %\listoftables
}

%*********************************************************
%**** Manual Glossary
%*********************************************************
\newpage
\section*{Glossary}
\begin{table}[h!]
\begin{tabular}{ll}     
c.p.       & ceteris paribus
\\ ~ \\               
\end{tabular}
\end{table}

%*********************************************************
%****BEGINN MAIN SECTION
%*********************************************************
%*********************************************************
%****PAGE NUMBERING
%*********************************************************
\pagenumbering{gobble}
\cleardoublepage
\pagenumbering{arabic}
\setcounter{page}{1}

%*********************************************************e
%****SET HEADER/FOOTER
%*********************************************************
\chead{\normalfont Title} %{Kopfzeile Mitte}
\ihead{{\normalfont Name}}%{Kopfzeile innen} %not italic
\ohead{\pagemark}%{Kopfzeile außen}
\ifoot%{Fußzeile innen}
\cfoot%{Fußzeile Mitte}
\ofoot%{Fußzeile außen}


\section{Introduction} \label{Introduction}
    \input{./Kapitel/Introduction}

\newpage
\section{Models} \label{Main}
    \input{./Kapitel/Main}
    
\newpage
\section{Conclusion} \label{Conclusion}
    \input{./Kapitel/Conclusion}

\newpage
 

\end{document}

Chapters Called I call chapter seperately. They lie in a folder called "Kapitel".

Abstract.tex

Abstract

Conclusion.tex

Conclusion

Introduction.tex

Introduction

Main.tex

\subsection{Model 1}


 \setcounter{equation}{0}
    \input{./Kapitel/Model1}
    
    \newpage
    blabla
    \newpage
    blabala
    \newpage
    
    \subsection{Model 2}
    \setcounter{equation}{0}
    \input{./Kapitel/Model2}

Model1.tex

\subsubsection{Equ1}
\begin{romanalignI}
\begin{align}
1+1 = 2 
\label{eq I.1}
\end{align}
\end{romanalignI}


\subsubsection{Eq 2}
\begin{romanalignI}
\begin{align}
1+1 = 2 
\label{eq I.2}
\end{align}
\end{romanalignI}

\subsubsection{Referencing both}
\eqref{eq I.1} and \eqref{eq I.2}.

Model2.tex

    \subsubsection{Equ1}
\begin{romanalignII}
\begin{align}
1+1 = 2 
\label{eq II.1}
\end{align}
\end{romanalignII}


\subsubsection{Eq 2}
\begin{romanalignII}
\begin{align}
1+1 = 2 
\label{eq II.2}
\end{align}
\end{romanalignII}

\subsubsection{Referencing both}
\eqref{eq II.1} and \eqref{eq II.2}.

I can't figure out what is causing the mess up and would be very, very thankful for any help!

11
  • 2
    try to minimize your failing example by removing one by one packages until you find the culprit. Jan 28, 2023 at 15:58
  • Welcome to TeX.SE. On fully updated MacTeX2022 distribution, I am unable to reproduce the issue you say you're getting. Please tell us which TeX distribution you employ and when you last updated it.
    – Mico
    Jan 28, 2023 at 16:04
  • Aside: You should almost certainly delete the preamble instruction \usepackage[latin1]{inputenc}. You'd also be well advised to replace \usepackage{times} with \usepackage{newtxtext,newtxmath}.
    – Mico
    Jan 28, 2023 at 16:05
  • 1
    Thanks for your comments! I am working with MiKTeX 21.3, last updated in April 2021... So that might well be the problem! I will update it and see if the problem persists.
    – EconCat
    Jan 28, 2023 at 16:17
  • About your equation numbering system: Do you simply want equations numbers to be displayed in the style \Roman{section}\arabic{equation}? And, should equation numbers be reset automatically whenever a \section directive is encountered?
    – Mico
    Jan 28, 2023 at 16:18

1 Answer 1

0

Modify the definitions into

% Römisch Erstens
\newcommand{\thealignedIal}{I.\arabic{equation}}

\makeatletter
\newenvironment{romanalignI}{%
    \let\theequation\thealignedIal
    \renewcommand\theHequation{\thealignedIal\arabic{equation}}%
    }{}
\makeatother

%% Römisch Zweitens
\newcommand{\thealignedIIal}{II.\arabic{equation}}
\makeatletter
\newenvironment{romanalignII}{%
    \let\theequation\thealignedIIal
    \renewcommand\theHequation{\thealignedIIal\arabic{equation}}%
    }{}
\makeatother

I also suggest to add \pagenumbering{Alph} before the titlepage and \pagenumbering{alph} after it, so you don't get duplicate anchors (the page numbering won't appear anyway). Never use \pagenumbering{gobble} when hyperref is involved.

1
  • Thanks a LOT, @egreg, this solution works flawlessly! Also thanks again to Mico for all of your helpful comments :)
    – EconCat
    Jan 28, 2023 at 17:55

You must log in to answer this question.

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