LoginSignup
14
9

More than 5 years have passed since last update.

LaTeXマクロでfor/whileループ

Last updated at Posted at 2015-02-15

LaTeXでfor/whileループが書ければ便利な時があります.
そんなときのマクロの書き方.どっちも同じです.

whileループ
\documentclass{jsarticle}

\newcount\K % int K                                                                             
\def\mywhile#1{%                                                                                
  \K=0 % K=0                                                                                    
  \loop\ifnum\K<10 % while(K<10)                                                                
    これがループ \number\K 回目です.% この行を実行                                               
  \advance\K by1% K++                                                                           
  \repeat % end while                                                                             
  }

\begin{document}

\mywhile{10} % ループ実行                                                                       

\end{document}
forループ
\documentclass{jsarticle}

\newcount\K % int K                                                                             
\def\myfor#1{%                                                                                  
  \K=0 \loop\ifnum\K<10 % for(K=0;K<10;K++)                                                     
  これがループ \number\K 回目です.% この行を実行                                               
  \advance\K by1\repeat % end for                                                               
  }

\begin{document}

\myfor{10} % ループ実行                                                                         

\end{document}

スクリーンショット 2015-02-15 16.33.53.png

14
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
9