2

I can use \let to rename

  • \curvepnodes to \ParametricNodes,

  • \Pnodecount to \LastIndexP as follows.

However, because \Pnodecount is generated dynamically inside \curvepnodes, I cannot move \let\LastIndexP\Pnodecount to the preamble or to a separate file.

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\let\ParametricNodes\curvepnodes

\begin{document}
\begin{pspicture}(-1,-1.5)(7,1.5)
    \ParametricNodes[plotpoints=50]{0}{2 Pi mul}{t|sin(t)}{P}
    \let\LastIndexP\Pnodecount
    \foreach \i in {0,...,\LastIndexP}{\psline(P\i|0,0)(P\i)}
\end{pspicture}
\end{document}

Question

How to rename a dynamically created macro \Pnodecount in the preamble or a separate file?

Note: The P in \Pnodecount is the node name specified in the last argument of \curvepnodes.

Edit 1

The objective is to have more intuitive names for both macros mentioned above. It does not matter what kind of methods you use to accomplish this issue, whether using patching, hijacking, injecting, renaming, copying, etc as long as I can do the patching, hijacking, injecting, renaming, copying, etc in the preamble or a separate file.

Edit 2

I am not interested in manual labor by writing

\def\LastIndexA{\Anodecount}

in the preamble after I use \curvepnodes...{A} in the body because renaming will be done automatically in a separate file (my own package).

  • your question isn't very clear, the dynamic aspect doesn't seem very relevant? even if \PnodeCount was a fixed name, it is locally defined just within each pspicture, so you clearly can not use the \let to make an alternative name outside the scope where the original command is defined? – David Carlisle Sep 12 '17 at 21:16
  • \let doesn't rename commands, it create copies. You are perhaps looking for \def\LastIndexP{\Pnodecount}. – Ulrike Fischer Sep 12 '17 at 21:16
  • And, did you try if \def solves your problem? – Ulrike Fischer Sep 12 '17 at 21:29
  • Well it works fine for me. So again, did you try, and if yes, what doesn't work as expected? – Ulrike Fischer Sep 12 '17 at 21:32
  • 1
    Sorry you probably didn't delete the preceding expandafter, I edited my answer – David Carlisle Sep 12 '17 at 22:46
1

If you have a command being defined by some code and you want it to define a different name in addition to the one it is defining, you need to change the code making the definition. In this case:

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\makeatletter
\let\curvepnodes@i@old\curvepnodes@i
\def\curvepnodes@i#1#2#3#4{%
  \curvepnodes@i@old{#1}{#2}{#3}{#4}%
  \expandafter\let\csname LastIndex#4\expandafter\endcsname
                  \csname#4nodecount\endcsname
  \ignorespaces}
\makeatother

\let\ParametricNodes\curvepnodes

\begin{document}
\begin{pspicture}(-1,-1.5)(7,1.5)
    \ParametricNodes[plotpoints=50]{0}{2 Pi mul}{t|sin(t)}{P}
    \foreach \i in {0,...,\LastIndexP}{\psline(P\i|0,0)(P\i)}
\end{pspicture}
\end{document}
  • @ArtificialStupidity not easily as there are all kinds of *-forms and optional arguments to be parsed over so you need to drop down to a level where they have been resolved. – David Carlisle Sep 12 '17 at 22:02
1
\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\let\ParametricNodes\curvepnodes
\def\LastIndexP{\Pnodecount}

\begin{document}
    \begin{pspicture}(-1,-1.5)(7,1.5)
    \ParametricNodes[plotpoints=50]{0}{2 Pi mul}{t|sin(t)}{P}
    \foreach \i in {0,...,\LastIndexP}{\psline(P\i|0,0)(P\i)}
    \end{pspicture}
\end{document}

enter image description here

  • It is not the solution that I want to achieve because it is impractical. – Money Oriented Programmer Sep 13 '17 at 7:00
  • \let\ParametricNodes\curvepnodes \makeatletter\let\LastIndexP\psk@plotpoints\makeatother should also work – user2478 Sep 13 '17 at 8:38
1

Since you need to know the affix at call time anyway, the simplest solution is to use a one argument macro.

% arara: latex
% arara: dvips
% arara: ps2pdf

\documentclass[pstricks]{standalone}
\usepackage{pst-plot}

\let\ParametricNodes\curvepnodes
\newcommand*{\LastIndex}[1]{\csname #1nodecount\endcsname}

\begin{document}
% original syntax
\begin{pspicture}(-1,-1.5)(7,1.5)
    \curvepnodes[plotpoints=50]{0}{2 Pi mul}{t|sin(t)}{P}
    \foreach \i in {0,...,\Pnodecount}{\psline(P\i|0,0)(P\i)}
\end{pspicture}
% "better" syntax
\begin{pspicture}(-1,-1.5)(7,1.5)
    \ParametricNodes[plotpoints=50]{0}{2 Pi mul}{t|sin(t)}{P}
    \foreach \i in {0,...,\LastIndex{P}}{\psline(P\i|0,0)(P\i)}
\end{pspicture}
% with a different name
\begin{pspicture}(-1,-1.5)(7,1.5)
    \ParametricNodes[plotpoints=50]{0}{2 Pi mul}{t|sin(t)}{Q}
    \foreach \i in {0,...,\LastIndex{Q}}{\psline(Q\i|0,0)(Q\i)}
\end{pspicture}
\end{document}

enter image description here

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.