Created
February 2, 2019 05:38
Star
You must be signed in to star a gist
TeX言語:表組み(alignment)中でチョット複雑なコードを動かすとアレ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% This code gives an error. | |
\documentclass[a4paper]{article} | |
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN | |
\newcount\xx@k \newcount\xx@n | |
% \EvenOddTable{<max-number>} | |
\newcommand*\EvenOddTable[1]{% | |
\global\xx@k=\z@ \global\xx@n=#1\relax | |
\begin{tabular}{cc}% | |
Even&Odd\\\hline | |
\@whilenum{\xx@k<\xx@n}\do{% | |
\global\advance\xx@k\@ne | |
\ifodd\xx@k | |
---&\the\xx@k\\% | |
\else | |
\the\xx@k&---\\% | |
\fi}% | |
\end{tabular}} | |
\def\xx@evenoddtable@a#1#2{% | |
#1\\} | |
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END | |
\begin{document} | |
\EvenOddTable{9} | |
\end{document} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% This code compiles successfully. | |
\documentclass[a4paper]{article} | |
\makeatletter %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code BEGIN | |
\newcount\xx@k \newcount\xx@n | |
% \EvenOddTable{<max-number>} | |
\newcommand*\EvenOddTable[1]{% | |
\global\xx@k=\z@ \global\xx@n=#1\relax | |
\begin{tabular}{cc}% | |
Even&Odd\\\hline | |
\@whilenum{\xx@k<\xx@n}\do{% | |
\global\advance\xx@k\@ne | |
\ifodd\xx@k | |
\xx@evenoddtable@a{---}{\the\xx@k}% | |
\else | |
\xx@evenoddtable@a{\the\xx@k}{---}% | |
\fi}% | |
\end{tabular}} | |
\def\xx@evenoddtable@a#1#2{% | |
#1\\} | |
\makeatother %!!!!!!!!!!!!!!!!!!!!!!!!! TeX code END | |
\begin{document} | |
\EvenOddTable{9} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
何がしたいのかについては、goodの方の組版結果を参照。
alignment tab(
&
)を含む部分を別のマクロに逃がすとエラーを回避できる。