# Arguments delimited by blank space in a macro

I work on postscript objects and I need to transform lines like

109.8516 58.404 moveto
102.7108 70.7583 88.4258 67.3824 82.4704 64.0235 curveto


or

109.8516 58.404 m
102.7108 70.7583 88.4258 67.3824 82.4704 64.0235 c


in the PGF/TikZ format. I have 20,000 lines and I also need to use as few number of characters as possible. A good solution is to avoid the braces and to keep the blank spaces. Actually, I use the following code:

\def\p#1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\m #1 #2 {\pgfpathmoveto{\p{#1}{#2}}}%
\def\l #1 #2 {\pgfpathlineto{\p{#1}{#2}}}%
\def\c #1 #2 #3 #4 #5 #6 {\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%


with

\m 109.8516 58.404
\c 102.7108 70.7583 88.4258 67.3824 82.4704 64.0235


The problem: I need to use a blank space at the end of each line and I would like to avoid this blank space. Moreover, I'm not sure if my code is correct.

Complement: My idea is to create a version of the psvectorian package for PGF/TikZ. I am translating the file psvectorian.pro to a file pgflibraryvectorian.code.tex. All the vector ornaments are created with the pgf basic layer. Perhaps it's not a good idea and I might try to compress this file. My project is here : pgfvectorian

-
Do you get these lines with \input or \read? –  egreg Jan 20 '12 at 15:57
I use a script to transform 109.8516 58.404 m and to get \m 109.8516 58.404. The first line come from a .eps file. –  Alain Matthes Jan 20 '12 at 16:28
Why not adding also a final delimiter? Change 109.8516 58.404 m into \m 109.8516 58.404\end and do \def\m#1 #2\end{\pgfpathmoveto{\p{#1}{#2}}} –  egreg Jan 20 '12 at 16:45
no because I get 20,000 \end in my file and I don't want this. I would like nothing after the last digit. –  Alain Matthes Jan 20 '12 at 16:52
It can be anything that's not a digit: Z, for instance; so the size wouldn't be affected. –  egreg Jan 20 '12 at 16:54

I would reformat the contents of pgflibraryvectorian.code.tex as follows:

\makeatletter

\def\pgf@@vectorian@p#1#2{\pgfqpoint{#1bp}{#2bp}}%
\def\pgf@@vectorian@m #1 #2Z{\pgfpathmoveto{\p{#1}{#2}}}%
\def\pgf@@vectorian@l #1 #2Z{\pgfpathlineto{\p{#1}{#2}}}%
\def\pgf@@vectorian@c #1 #2 #3 #4 #5 #6Z{%
\pgfpathcurveto{\p{#1}{#2}}{\p{#3}{#4}}{\p{#5}{#6}}}%

\def\pgf@@vectorian#1{%
\begingroup
\let\p\pgf@@vectorian@p
\let\m\pgf@@vectorian@m
\let\l\pgf@@vectorian@l
\let\c\pgf@@vectorian@c
\@nameuse{pgf@@vectorian@#1}%
\endgroup}

\@namedef{pgf@@vectorian@1}{%
%def\@pgfvectorianX{136}\def\@pgfvectorianY{107}%   vec1
\m 109.8516 58.404Z
\c 102.7108 70.7583 88.4258 67.3824 82.4704 64.0235Z
\c 76.5236 60.6518 72.9472 60.6518 69.3794 75.2496Z
\c 65.7988 89.856 49.1309 90.9713 38.418 90.9713Z
\c 27.7056 90.9713 32.4678 106.6973 32.4678 106.6973Z
\c 9.8485 79.7409 25.3228 66.2628 38.418 62.8953Z
\c 51.5219 59.5279 49.2228 58.0494 34.8502 49.4172Z
\c 21.7545 41.5499 27.7056 31.4434 24.1335 19.0934Z
...
\c 87.4827 79.2025 91.3928 77.6427 105.0731 80.4119Z
\pgfpathclose
\pgfusepath{fill,stroke}}

\@namedef{pgf@@vectorian@2}{%
%def\@pgfvectorianX{133}\def\@pgfvectorianY{48}%     vec2
\m 132.9548 23.3771Z
\c 131.3683 31.9185 119.1886 48.1506 83.3983 47.7588Z
...
\pgfpathclose
\pgfusepath{fill,stroke}}

...

\makeatother
\endinput


This avoids both having a gigantic \ifcase in one macro and the problem of terminating the \l, \m and \c macro arguments with an invisible final space.

-
Little mistake \@nameuse{pgf@@vectorian@#1}% you forgot the second @. I take your code but I replace \let\m... by \def\m ##1 ##2 {\pgfpathmoveto{\p{##1}{##2}}}% and I remove the first \def. Something very strange : I keep on using ##1 ##2 with a blank space after 2 and I remove all the blank spaces at the end of lines. The code seems to compile correctly. Why ? EOF is like a blanck space ? –  Alain Matthes Jan 20 '12 at 23:05
@Altermundus Yes, at the end of a line there's always ^^M that TeX converts into a space provided another ^^M doesn't follow. This is why delimiting the final argument with a space is risky. –  egreg Jan 20 '12 at 23:22