1

Consider the following example where the code is taken from https://tex.stackexchange.com/a/399817/15874 and modified a bit:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{xfp}
\usepackage{xskak}

\def\svarstedB{3.7em}
\newcommand*\hestB[2][\svarstedB]{%
  \underline{\makebox[\ifdim\width>#1\width\else#1\fi]{#2}}}
\newcommand*\matLoesninger[1]{\hestB{\textcolor{blue}{\smash{#1}}}}

\newcommand*\matTo[6]{%
  \def\tempA{#1}%
  \def\tempB{#2}%
  \def\tempC{#3}%
  \def\tempD{#4}%
  \def\tempE{#5}%
  \def\tempF{#6}%
  \matToEkstra}
\newcommand*\matToEkstra[5]{%
\begin{figure}[!htbp]
 \LARGE
 \centering
  \begin{minipage}{0.5\textwidth}
   \centering
    \ifblank{\tempA}{\vphantom{1}}{\textbf{\tempA}}%
    \vspace*{-2ex}

    \scalebox{1}{\newchessgame[setfen = \tempC\space \tempB - - 0 1, print]}%

    \hspace*{1.2em} Hvid \hspace*{2em} Sort
    \vspace*{-1ex}

    \begin{flushleft}
      \ifstrequal%
        {\tempB}{w}%
        {\hspace*{1.1em}%
         1.%
         \hspace*{0.6em}%
         \matLoesninger{\tempD}%
         \hspace*{0.8em}%
         \matLoesninger{\tempE}%
         \vspace*{0.6ex}

         \hspace*{1.1em}%
         2.%
         \hspace*{0.6em}%
         \matLoesninger{\tempF}}%
        {\hspace*{1.1em}%
         1.%
         \hspace*{5.1em}%
         \matLoesninger{\tempD}%
         \vspace*{0.6ex}

         \hspace*{1.1em}%
         2.%
         \hspace*{0.6em}%
         \matLoesninger{\tempE}%
         \hspace*{0.8em}%
         \matLoesninger{\tempF}}%
    \end{flushleft}
  \end{minipage}%
  \begin{minipage}{0.5\textwidth}
   \centering
    \ifblank{\tempA}{\vphantom{1}}{\textbf{\fpeval{\tempA+1}}}%
    \vspace*{-2ex}

    \scalebox{1}{\newchessgame[setfen = #2 #1 - - 0 1, print]}%

    \hspace*{1.2em} Hvid \hspace*{2em} Sort
    \vspace*{-1ex}

    \begin{flushleft}
      \ifstrequal%
        {#1}{w}%
        {\hspace*{1.1em}%
         1.%
         \hspace*{0.6em}%
         \matLoesninger{#3}%
         \hspace*{0.8em}%
         \matLoesninger{#4}%
         \vspace*{0.6ex}

         \hspace*{1.1em}%
         2.%
         \hspace*{0.6em}%
         \matLoesninger{#5}}%
        {\hspace*{1.1em}%
         1.%
         \hspace*{5.1em}%
         \matLoesninger{#3}%
         \vspace*{0.6ex}

         \hspace*{1.1em}%
         2.%
         \hspace*{0.6em}%
         \matLoesninger{#4}%
         \hspace*{0.8em}%
         \matLoesninger{#5}}%
    \end{flushleft}
  \end{minipage}
\end{figure}}

\begin{document}

\matTo%
  {15}%
  {w}{5r1k/ppq4p/4p2p/2PnNp2/5P2/P6P/1B4P1/5R1K}{Sf7+}{Kg8}{Sxh6\#}%
  {b}{5rk1/1pp4p/p3R1p1/3R1n2/6B1/2P5/2PQ2PP/5K2}{Sg3+}{Ke1}{Tf1\#}

\end{document}

It doesn't matter if I set the value of the second argument of \matTo to b or w, the macro registres it as not being w. (The code works just fine for the chessboard printed inside the minipage to the right but not the one printed to the right.)

What is wrong with my macro and how do I fix it?

(It's probably really easy but I simply can't find the error. :-()

I simply don't understand why the

\ifstrequal%
  {\tempB}{w}

part of my macro inside the first minipage is wrong.

P.S. Don't look at the page layout when the chessboards are printed; it's really ugly at the moment.

  • 1
    Side remark: In my opinion your code is unreadable and unmaintainable. Why do you insist to write commands with 11 arguments? Why all this temp-commands without meaning? And why do you mix layout and calculations in this way? Why do write commands which are nearly 100 lines long? – Ulrike Fischer Nov 23 '17 at 21:40
  • @UlrikeFischer Please feel free to shorten and/or simplify the code. :-) – Svend Tveskæg Nov 23 '17 at 21:43
  • @DavidCarlisle Not sure ... I'm still doing something wrong. Any chance I can make you change my code in order for it to work as I would like it to? (I'm probably just confusing myself now and I get more and more frustrated ...) – Svend Tveskæg Nov 23 '17 at 21:52
  • I have no idea the code is as Ulrike indicated rather long and confusing and you give little indication what it is supposed to do, i just observed you are testing if #1 iw w but in your example #1 is 15 and #2 is w, so that looked wrong. – David Carlisle Nov 23 '17 at 21:57
  • @DavidCarlisle: The command has actually 11 argument as two commands are chained and #1 is #6 (or something like this). – Ulrike Fischer Nov 23 '17 at 22:00
2

From the documentation of xskak:

All chessboard keys are processed normally. You can even print directly the board by using the key print. The only exceptions are the keys maxfield and zero that change the size of the board – skak doesn’t like unusual sizes of the board – and the keys mover and fullmove which are overwritten by the (eventually default) value of key moveid

This means that if you want to set the mover, you should either add the player explictly in \newchessgame, or use \chessboard to print the board:

\documentclass{article}

\usepackage{etoolbox}
\usepackage{xfp}
\usepackage{xskak}

\setchessboard{tinyboard}
\begin{document}
\newchessgame[setfen=5rk1/1pp4p/p3R1p1/3R1n2/6B1/2P5/2PQ2PP/5K2 b - - 0 1,print] % wrong

\newchessgame[setfen=5rk1/1pp4p/p3R1p1/3R1n2/6B1/2P5/2PQ2PP/5K2 b - - 0 1,player=b,print] % correct

\chessboard[setfen=5rk1/1pp4p/p3R1p1/3R1n2/6B1/2P5/2PQ2PP/5K2 b - - 0 1]

\end{document}

enter image description here

Edit

As answer to the comment:

You are using the wrong command for the test: \ifstrequal doesn't expand the strings.

\documentclass{article}

\usepackage{etoolbox}

\begin{document}
\def\tempB{w}

\ifstrequal{\tempB}{w}{true}{false}
\ifdefstring{\tempB}{w}{true}{false}
\end{document}

enter image description here

  • I wasn't explaining myself correctly (sorry!). The actual problem is with the position of the line segments underneath the diagrams. I want the position to change depending on whether I choose w or b as the second argument of my macro. This works for the diagram to the left (via the seventh argument of the macro) in my code but not for the diagram to the right and I don't know why. – Svend Tveskæg Nov 23 '17 at 21:49
  • 1
    I added an edit. – Ulrike Fischer Nov 23 '17 at 21:56
  • Finally, I got it! Thank you very much, Ulrike! ... If you can make my code more readable, I would be very interested in seeking what you can come up with. :-) – Svend Tveskæg Nov 23 '17 at 22:16
  • I'll accept your answer shortly ... also if you don't improve on my code, of course. – Svend Tveskæg Nov 23 '17 at 22:20
  • 1
    Sorry but as I already wrote: your code is basically unreadable. It would take an hour to find out what you are trying to achieve and why you use the various command (e.g. the figure, all the smash and more) and then one would have to rewrite the code from scratch. That's too much time for one answer. – Ulrike Fischer Nov 23 '17 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.