TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

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.