Skip to content

Instantly share code, notes, and snippets.

@nonchris
Created June 12, 2021 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonchris/c49d9b998eb6fd80dd2d6cd57d03b577 to your computer and use it in GitHub Desktop.
Save nonchris/c49d9b998eb6fd80dd2d6cd57d03b577 to your computer and use it in GitHub Desktop.
A basic loop written in tex
% NOTE: I do not guarantee that this is the best way of doing it
% but I wanna share it anyways since I can't really find any (commented) example code like this.
% ---
% command to print numbers one per line
% paste somewhere into your document (can be preamble or document itself)
% init counter variable
\newcount\i
% define macro with one input (integer)
\def\basicLoop#1{
% init loop with breaking condition - kind of a whiel loop
% check if counter is less than input
\loop \ifnum \i < #1
% print counter
\number\i
% increment i by one
\advance\i by 1
% go to the beginning
\repeat
% print word done
done
}
% call function
\basicLoop{4}
@nonchris
Copy link
Author

If you'd like to lean more about tex programming, have a look at the answer of this question.

https://tex.stackexchange.com/questions/12668/where-do-i-start-latex-programming

@nonchris
Copy link
Author

If you'll need to to the whole code as a one-liner to print the numbers in one line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment