
Ich verwende Code (leicht angepasst) vondiese Antwortum Polyominoes zu rendern. Es funktioniert großartig, bis auf zwei Probleme.
Die Länge von Polyominoes mit nur einer Reihe scheint nicht berücksichtigt zu werden.
Das zweite Problem ist, dass ich die erste Reihe immer mit Abstandshaltern füllen muss, damit der Abstand richtig funktioniert. (Das ist nur ein Ärgernis und nicht so kritisch wie das erste Problem).
Weiß jemand, wie ich das beheben kann?
Hier ist ein Minimalbeispiel:
\documentclass{article}
\makeatletter
\def\omino#1{{%
\unitlength6\p@
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xomino#1\relax
\begin{picture}(\@tempcnta,\@tempcntb)(0,-\@tempcntb)%
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xxomino#1\relax
\end{picture}%
}%
}
\def\xomino#1{%
\ifx\relax#1%
\else
\ifx\\#1%
\ifnum\count@>\@tempcnta \@tempcnta\count@\fi
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne
\fi
\expandafter\xomino
\fi}
\def\xxomino#1{%
\ifx\relax#1%
\else
\ifx\\#1%
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne
\ifx*#1%
\put(\count@,-\@tempcntb){\kern-6pt\framebox(0.93,0.93)}
\fi
\fi
\expandafter\xxomino
\fi}
\makeatother
\begin{document}
Polyominoes with two or more rows like this \omino{*****\\*\\*}
work great, but polyominoes that have only one row like this
\omino{******} don't align properly.
Also, the first row needs to be complete, like this \omino{*...\\****}
to work. Without the empty characters, the polyomino is not spaced
correctly, like \omino{*\\****}this.
\end{document}
Antwort1
Das Problem besteht darin, dass bei der Berechnung der maximalen horizontalen Schritte die letzte Zeile nicht berücksichtigt wird. Dies kann man beheben, indem man die maximale Berechnung im \\
Fall zum \relax
Fall hinzufügt. Die Änderung wird mit einem gekennzeichnet %<-
.
\documentclass{article}
\makeatletter
\def\omino#1{{%
\unitlength6\p@
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xomino#1\relax
\begin{picture}(\@tempcnta,\@tempcntb)(0,-\@tempcntb)%
\@tempcnta\z@
\@tempcntb\@ne
\count@\z@
\xxomino#1\relax
\end{picture}%
}%
}
\def\xomino#1{%
\ifx\relax#1%
\ifnum\count@>\@tempcnta \@tempcnta\count@\fi%<-
\else
\ifx\\#1%
\ifnum\count@>\@tempcnta \@tempcnta\count@
\fi
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne%
\fi
\expandafter\xomino
\fi}
\def\xxomino#1{%
\ifx\relax#1%
\else
\ifx\\#1%
\advance\@tempcntb\@ne
\count@\z@
\else
\advance\count@\@ne
\ifx*#1%
\put(\count@,-\@tempcntb){\kern-6pt\framebox(0.93,0.93)}
\fi
\fi
\expandafter\xxomino%
\fi}
\makeatother
\begin{document}
Polyominoes with two or more rows like this \omino{*****\\*\\*}
work great, but polyominoes that have only one row like this
\omino{******} don't align properly.
Also, the first row needs to be complete, like this \omino{*...\\****}
to work. Without the empty characters, the polyomino is not spaced
correctly, like \omino{*\\****} this.
\end{document}