Math & ScienceRecommend an \ifnum introduction

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Recommend an \ifnum introduction

Post by LaTexLearner »

Can anybody recommend an introduction to the \ifnum commands?

I can't make sense of code that has them but I'd like to learn how they work.

Thanks!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Recommend an \ifnum introduction

Post by cgnieder »

\ifnum is a TeX primitive conditional for comparing integers:

Code: Select all

\ifnum1=1
  true
\else
  false
\fi % yields true

\ifnum1<2
  true
\else
  false
\fi % yields true

\ifnum1>2
  true
\else
  false
\fi % yields false

\bye
\ifnum and all other primitives are explained in the TeX book or in TeX by topic: texbytopic.

Regards
site moderator & package author
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Recommend an \ifnum introduction

Post by Stefan Kottwitz »

Perhaps you may also be interested in the ifthen package.

Also, some modern packages such as pgf provide tools for comparing or calculating. More complex calculations could be done using LuaTeX. I use LuaTeX and binary math for calculating subnet IP addresses, for example.

Stefan
LaTeX.org admin
Post Reply