Menu

#368 \foreach command fails with macros as argument

v1.0 (example)
closed-wont-fix
nobody
foreach (4)
5
2018-12-24
2015-09-01
No

The following command does not produce the expected result (the command is defined in
pgffor.code.tex):

\def\mysequence{U,D,L,R,B,F}
\foreach\x in {\mysequence}{\fbox{\x},\ }

I have created a simple patch that solves the problem and of course the command

\foreach\x in {U,D,L,R,B,F}{\fbox{\x},\ }

continues to work as expected.

Please consider upadating the code of pgffor.code.tex

1 Attachments

Discussion

  • percusse

    percusse - 2015-09-06

    Hi Apostolos.

    You have to use a single brace group for this usage, so you need to remove the brace around \mysequence

    \foreach\x in \mysequence{\fbox{\x},\ }
    
     
  • Apostolos Syropoulos

    Well I do not agree! Suppose one defines the following command:

    \newcommand{\myspot}{U,D,L,R}
    

    and uses this command to define the command that follows

    \newcommand{\mypattern}{x,y,U,\myspot,L,R,y}
    

    Then, \foreach\x in \mypattern{\fbox{\x},\ } will not yield
    the expected result. And this is not some theoretical exercise.
    Someone needs this facility in package that he is working on.
    Thus this patch is the only way to make the \foreach command
    work as it should. BTW, when one types

    \foreach\x in {U,D,L,R,B,F}{\fbox{\x},\ }
    

    it is more natural to type

    \foreach\x in {\myspot}{\fbox{\x},\ }
    

    instead of

    \foreach\x in \myspot {\fbox{\x},\ }
    
     

    Last edit: Stefan Pinnow 2018-12-23
    • percusse

      percusse - 2015-09-08

      Hi Apostolos,

      Your analogies are not compatible, one is about stripping off braces to understand the context and the other one is expansion control. Braces are not throw-away containers, they actually mean something hence their usage is not about consistency. It is a TeX quirk but it is what it is. You cannot expect consistent syntax from an in-place replacement engine.

      TikZ needs to see explicit characters (via \pgfutil@ifnextchar) to branch off hence your natural syntax will break other things and it is certainly not the only way as I have demonstrated. I don't know what the developers think but I don't agree that your patch is the way to go.

      And finally, there is nothing natural about TeX.

       
  • Apostolos Syropoulos

    To make this discussion sort: You simply do not want to understand and therefore you do not want to modify the code. It is your package, your work and finaly your idiosyncrasy.

     

    Last edit: Apostolos Syropoulos 2015-09-08
    • percusse

      percusse - 2015-09-08

      Sorry that you feel that way but it is NOT my package. I'm a user and I tried to show you an alternative and one possible reasoning this is not a good idea because I understand what you are doing in the patch. There is no need to go sour if someone disagrees with you. You can wait until the developers respond instead.

       
  • Apostolos Syropoulos

    I posted the initial message to the developers. Not to some public forum where people argue about everything. If you are not on of the developers, please wait until they step in and make a decision and if you happen to hate their decision you can fill in a bug report. Inaddition, I posted the patrch as a possible solution and not as the solution. And finally this is a bug and it would be a good idea to fix it. No one is obliged to fix it.

     
    • percusse

      percusse - 2015-09-08

      Nice attitude from a person whose previous words were Thus this patch is
      the only way to make the \foreach command work as it should
      . Anyway, let's
      not discuss further. There is no point.

       

      Last edit: percusse 2015-09-12
  • Apostolos Syropoulos

    That's the on;y thing I agree with you. BTW, it would be nice to know to whom I am talking! Hiding your identity is not a good thing to do.

     
  • Henri Menke

    Henri Menke - 2018-12-24

    The proposed patch contradicts the documented behaviour. Close as wont-fix.

     
  • Stefan Pinnow

    Stefan Pinnow - 2018-12-24
    • status: open --> closed-wont-fix