LaTeX forum ⇒ Math & ScienceRecommend an \ifnum introduction

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

Recommend an \ifnum introduction

Postby LaTexLearner » Sun Sep 18, 2016 9:13 pm

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!

Tags:

User avatar
cgnieder
Site Moderator
Posts: 1974
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:

Postby cgnieder » Sun Sep 18, 2016 9:51 pm

\ifnum is a TeX primitive conditional for comparing integers:

  1. \ifnum1=1
  2. true
  3. \else
  4. false
  5. \fi % yields true
  6.  
  7. \ifnum1<2
  8. true
  9. \else
  10. false
  11. \fi % yields true
  12.  
  13. \ifnum1>2
  14. true
  15. \else
  16. false
  17. \fi % yields false
  18.  
  19. \bye


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

Regards
Clemens
------------------------------
chemmacros · chemformula · leadsheets · xsim

User avatar
Stefan Kottwitz
Site Admin
Posts: 8541
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Mon Sep 19, 2016 10:23 am

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
Site admin


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 2 guests