GeneralCurrent chapter number variable

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ProbablyNotYou
Posts: 3
Joined: Mon Jul 08, 2024 8:44 am

Current chapter number variable

Post by ProbablyNotYou »

Hello,

I'm searching for a way to automatically set labels depending on in which chapter the labeled item is in. Something like a variable that contains the current chapter number, is what I'm looking for. I want to use a selfmade section, that is automatically labeled, so that I can reference it by:[chapternumber . sectionnumber] (In which the sectionnumber is the by me given number). It should look something like this, if \currentchapter contained the current chapter number:

Code: Select all

Code, edit and compile here:
\documentclass[11pt,titlepage,a4]{report}
\usepackage{hyperref}
\newcommand{\ownsection}[1]{\section{Definition #1}\label{\currentchapter.#1}}
\begin{document}
\chapter{Exponential Equations}
\ownsection{1}
something
\chapter{Next}
Exponential Equations are defined as in \hyperref[1.1]{Definition 1}.
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
In PDF I want it to look like:

Chapter 1
Exponential Equations


Definition 1
something


Chapter 2
Next


Exponential Equations are defined as in Definition 1.

I'm looking forward to any help :).
Thanks a lot!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10329
Joined: Mon Mar 10, 2008 9:44 pm

Current chapter number variable

Post by Stefan Kottwitz »

Welcome to the forum!

You can use \thechapter:

Code: Select all

\newcommand{\ownsection}[1]{\section{Definition #1}\label{\thechapter.#1}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Stefan
LaTeX.org admin
ProbablyNotYou
Posts: 3
Joined: Mon Jul 08, 2024 8:44 am

Current chapter number variable

Post by ProbablyNotYou »

Thank you for the fast answer!
It works like a charm, exactly as I wanted!
Post Reply