When defining parameters for the \draw command in a \NewDocumentCommand setting [help lines] is rejected, as are some other arguments, for example [ultra thin] etc., but [lime,thin] etc. are OK. Could there be something askew in the handling of the Expl3 key-value interface in TikZ? Evidentally, no such problems occur if using the LaTeX2 \newcommand.

% RN. 28 March 2017
    %\draw [help lines] (0,0) grid (#1,#1); => compiler ERROR
    \draw [lime,thin] (0,0) grid (#1,#1);
  \myGrid [10]
  • 1
    Well, in the expl3 regime, your spaces are ignored, i.e. help lines is seen as helpline which is most likely undefined. Your command does not make any use of expl3 features, so why do you use \ExplSyntaxOn there -- the \NewDocumentCommandetc. macro do not need it all (as front-end to expl3) – user31729 Mar 28 '17 at 12:07
  • 3
    In that situation you would need help~lines (or help ~ lines, if you want it to look a bit more spaced up), because “spaces” are input with ~ inside expl3 code. – Manuel Mar 28 '17 at 12:11
  • @Manuel: Yes, but since there are some pgfkeys with spaces inside, it will get tedious to preserve for them with ~ inside – user31729 Mar 28 '17 at 12:13
  • @ChristianHupfer Yes, no doubt. I even asked to ignore spaces in expl3 keys as a result related of this problem with pgfkeys. But if it's for a few keys in a macro definition, then there's no problem with issuing ~. – Manuel Mar 28 '17 at 12:15
  • @Manuel: Yes, for some few occurences this is perfectly alright. – user31729 Mar 28 '17 at 12:16

The tilde is the "space" in the expl3 language, so whenever you need a real space, e.g., in strings or in keys as in your example you need to add a "space" which inside expl3 regime is visually looking like a tilde.

Now there are good arguments for making the normal space ignored and once you are used~to~write~strings~like~this~ or~ this~ it isn't that tedious (and much easier to correct if forgotten compared to finding the issue caused by a missing percent in LaTeX2e code).

Of course if you have to write many strings in your code (or the tilde is not easily usable with your keyboard) then it is a little less convenient, but on the whole that convention of expl3 has helped a lot to get much more readable code and much less errors due to forgotten % characters in important places (that result in tiny extra spaces in the output that are hard to track --- much harder than astringwhereforsomereasonthespacesaremissing.

  • One should also point out that ~ in the replacement text of a macro is normalized to a space token with character code 32 and category code 10, so when the TikZ scanning takes place, spaces are found where they should. Moreover, ~ is not removed at end of lines. – egreg Mar 28 '17 at 22:18
  • I'm not entirely convinced by this. However, I'm not entirely conviced the other way either. Except for PGF/TikZ. There it really is much trickier with Expl3 syntax active and I'd advise avoiding it, myself. – cfr Mar 28 '17 at 23:17
  • I have learnt to appreciate the ~, slowly but surely. It certainly has fixed the problem here. Much obliged. While I am sure that @cfr makes a valid point when advising to separate the "normal package environment" from Expl3 and put TikZ stuff into the former, the argument goes over my head technically. I pretend that Expl3, which provides me with the\NewDocumentCommand and similar document level commands as well as the many functions introduced in the various references, is all there is and continue to refuse to look under the hood. – Reinhard Neuwirth Mar 29 '17 at 1:13

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.