3

When using infix-RPN package, we can use \infixtoRPN to convert infix expression to RPN expression. The output of the conversion can be retrieved by invoking \RPN.

\infixtoRPN{cos(x)+sin(x)}, for example, will yield x cos x sin add that is available in \RPN.

My question, how to insert RadtoDeg right after the x? So the final will be x RadtoDeg cos x RadtoDeg sin add.

The skeleton is given as follows.

\documentclass{article}
\usepackage{infix-RPN}

\def\f(#1){cos(#1)+sin(#1)}

% #1 target word
% #2 inserted word
\def\appendtoRPNafter#1#2{%
    %implementation using \RPN goes here!
    %don't forget to return the result!
}
\begin{document}
    \infixtoRPN{\f(x)}%
    \appendtoRPNafter{x}{RadtoDeg}%
\end{pspicture}
\end{document}
4

(Your MWE doesn't W)

\documentclass{article}
\usepackage{infix-RPN}

\def\f(#1){cos(#1)+sin(#1)}

    \infixtoRPN{\f(x)}%

\typeout{A: \RPN}

% #1 target word
% #2 inserted word
\def\appendtoRPNafter#1#2{%
\def\tmp##1 #1 ##2{##1\ifx\tmpb##2\else\space #1 #2 \expandafter\tmp\fi##2}%
\def\tmpb.{}%
\edef\RPN{\expandafter\tmp\RPN\tmpb. #1 \tmpb.}
}

    \appendtoRPNafter{x}{RadtoDeg}%

\typeout{B: \RPN}

\stop

Produces terminal output of

A:  x cos x sin add
B:  x RadtoDeg cos x RadtoDeg sin add

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.