I was trying to define a command \runx, which not only evaluates a Haskell expression (this is what \perform already does), but also prints the expression before the evaluation.

So I tried

\newcommand{\runx}[1]{result=\ttfamily{#1} \perform{#1} }

and use it like


It turns out the expression sent to ghci is a literal #1 and not pi. So \perform is obviously applied too early for my purpose, namely at the time when the command is defined. Ghci returns nothing useful when asked to evaluate #1 and \perform{#1} evaluates to nothing.

  • Thus \runx{pi} becomes
  • {result=\ttfamily{pi} \perform{#1} } which becomes
  • {result=\ttfamily{pi}}

Thus the result of evaluating pi is lost in my pdf document, and I only see:

enter image description here

Is there a way to make \perform less eager?

  • 1
    the content of a \newcommand is not executed at all at the point of definition \perform need not even be defined. I assume \perform is a verbatim-like command so can not be used as you use it here in the definiton of another command, but that wouldn't affect an argument like pi only if the argument had special characters that need to be read verbatim – David Carlisle Oct 20 '17 at 12:41
  • 1
    oh unless you are using a preprocessor that replaces \perform by the results ghc evaluation before the tex is run, rather than tex executing external commands as encountered? – David Carlisle Oct 20 '17 at 12:44
  • This is most likely the case. I believe \perform is not really a TEX thing, but an instruction to the lhs2tex preprocessor. Unfortunately it looks like a TEX thing for some reason. So this question is really specific to lhs2tex. – Martin Drautzburg Oct 20 '17 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.