Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 230

LaTeX returning lists from helper commands

$
0
0

I am attempting to use a helper function to remove a number from a list, specifically for Sudoku puzzle pencil marks in my case. In the following code, I'm unable to get the function to return the updated list (I haven't even reached the point of handling empty lists yet).

How can I return a modified list from the function and save that updated list so I can continue removing more entries? Thus I would expect the output to be 1,2,3,4,7,8,9. The 5 and 6 removed from the list.

\documentclass{article}\usepackage{pgfmath} \begin{document}% Helper macro to remove a number from the list and return the modified list\newcommand{\removeNumber}[2]{%    \pgfmathparse{int(#2)} \let\entry\pgfmathresult % Ensure integer format    \edef\temp{} % Reset temporary storage    \foreach \n in #1 {%        \ifnum\n=\entry        \else            \ifx\temp\empty                \edef\temp{\n} % Insert first element            \else                \edef\temp{\temp,\n} % Append remaining numbers            \fi        \fi    }    \message{Temp Result: \temp} % Print in log    \texttt{Temp Result: \temp} % Print in document    \temp % Return the modified list}% Sudoku pencil marks\newcommand{\testRemoveNumber}{%    \edef\candidatesList{1,2,3,4,5,6,7,8,9} % Define a list    \edef\result{\candidatesList} % Initialize square with full list    % Remove 5    \edef\result{\removeNumber{\result}{5}}     % Remove 6 from the updated list    \edef\result{\removeNumber{\result}{6}}     \message{Remaining candidates: \result} % Print in log    \texttt{Remaining candidates: \result} % Print in document}% Call the macro\testRemoveNumber\end{document}

Viewing all articles
Browse latest Browse all 230

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>