Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

(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
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.