-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
declare function
: Strip spaces around each function arg
#1124
base: master
Are you sure you want to change the base?
Conversation
@@ -184,7 +184,7 @@ | |||
\expandafter\pgfmath@toks\expandafter=\expandafter{\pgfmath@local@body}% | |||
\else% | |||
\pgfmath@toks={}% | |||
\expandafter\pgfmath@local@function@@body\pgfmath@local@args,,% | |||
\expandafter\pgfmath@local@function@@body@trimspaces\pgfmath@local@args,,% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\exp_last_unbraced:No
fits this case, but it won't obviously increase the readability.
% original text unexpanded in the input stream. Same as \trim@spaces@noexp | ||
% in trimspaces.sty | ||
\def\pgfutil@trimspaces@noexp#1{% | ||
\unexpanded\expandafter\expandafter\expandafter{\pgfutil@trimspaces{#1}}% |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a pity that there's no expl3
function to handle this two-step expansion case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\exp_args:Nf
should do that. It basically equals \expandafter#1\expandafter{\romannumeral-`0#2}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We used to have them (d
-type), but there are very few places we found we needed them - as we've required e-TeX for a long time, we've been able to rely on most functions including \unexpanded
to protect their return values. Also, now we have \expanded
, we can use that ... sorry it doesn't work quite so well for you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I have in my mind is sth more general (and/but less efficient, of course), like \exp_by_steps:nn {<num of steps>} {<tokens>}
\documentclass{article}
\usepackage{pgfmath}
\ExplSyntaxOn\makeatletter
% Expand #2 by exactly #1 steps and leaves the result in input stream.
% The result is returned within \unexpanded.
\cs_new:Npn \exp_by_steps:nn #1#2
{
\int_compare:nNnTF {#1} > 0
{
\exp_by_steps:eo { \int_eval:n {#1-1} } {#2}
}
{
\exp_not:n {#2}
}
}
\cs_generate_variant:Nn \exp_by_steps:nn {eo}
\exp_args:Ne \tl_show:n { \exp_by_steps:nn {0} {\undefined} }
\exp_args:Ne \tl_show:n { \exp_by_steps:nn {1} {\tl_if_eq:ccTF} }
\exp_args:Ne \tl_show:n { \exp_by_steps:nn {2} {\pgfutil@trimspaces{ \x}} }
\makeatother\ExplSyntaxOff
\begin{document}
\end{document}
% > \undefined .
% > \exp_args:Ncc \tl_if_eq:NNTF .
% > \x .
Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
bc507c1
to
95ac3bc
Compare
@@ -910,5 +919,6 @@ | |||
\endgroup | |||
}% | |||
\input pgfutil-common-lists.tex | |||
\input pgfutil-common-expl.tex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be inlined into pgfutil-common.tex
directly. Loading files in TeX is slow. @josephwright promised to develop some kind of luadocstrip for l3build to merge files during build. Once that arrives we can split it again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made inlined in commit 190342a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since pgfutil-<format>.def
is loaded after pgfutil-common.tex
, all wrapped primitives [1] are undefined in pgfutil-common.tex
. We have to pay attention to not actually expand any of them in defining pgfexpl
macros. Not sure if this is achievable in the long term.
[1] Currently there're \pgfutil@protected
and \pgfutil@unexpanded
. \pgfutil@expanded
should be added (see also #1028).
force pushed to add a changelog entry |
% for expl3 macros. | ||
% | ||
% Naming conventions: | ||
% pgf_cs = "pgfexpl@" + expl3_cs.replace("_", "@").replace(":", "@@") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with a little bit of work we could make _
a letter. There are very few uses of _
outside of \write
and comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
is a bit more difficult, because it's used in \pgfutil@ifnextchar
(and some other stuff that needs to skip spaces).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doable. Do you expect it happens in current PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say yes, because we should address this immediately as pgfexpl
is introduced. However, if you can't do it in a timely manner, we can go ahead without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about
% Naming conventions:
% pgf_cs = "__pgfexpl_" + expl3_cs.replace(":", "@")
% For example,
% expl3_cs: \exp_args:Ne, \tl_put_right:Nn
% pgf_cs: \__pgfexpl_exp_args@Ne, \__pgfexpl_tl_put_right@Nn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:
is a bit more difficult, because it's used in\pgfutil@ifnextchar
(and some other stuff that needs to skip spaces).
Since the ultimate goal is to depend on expl3-code.tex
, now I'm kind of leaning more towards making both _
and :
letters at once. A constant token list \c__pgfexpl_semicolon_tl
and some careful expansion works will overcome the :
issue.
which are drop-in replacements for expl3 functions Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
95ac3bc
to
1e9cf84
Compare
This commit should be ammended to existing ones when the PR is approved Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
4d14f2d
to
169908a
Compare
This commit should be ammended to existing ones when the PR is approved. Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
This commit should be ammended to existing ones when the PR is approved. Signed-off-by: muzimuzhi <muzimuzhi@gmail.com>
This PR is blocked by #1116. |
Motivation for this change
To reduce the use of
\expandafter
and make the code more readable, some\pgfexpl@xxx
macros are introduced.Fixes #1123
Checklist
Please signoff your commits to explicitly state your agreement to the Developer Certificate of Origin. If that is not possible you may check the boxes below instead: