[Haskell-cafe] Re: A 3 line program --> Mauricio

Philippos Apolinarius phi500ac at yahoo.ca
Sun Oct 25 00:17:26 EDT 2009

Hi, Mauricio.
Since LaTeX reserves inverted slashes for internal use, I cannot tamper with it.  The idea is to transfer the problem to Haskell (or Clean, or Scheme), not to LaTeX. After all, it is easier to program in Haskell, Clean or Scheme than in LaTeX. Anyway, here is what happens if I follow your suggestion:

-- File tudin.hs
import Htudin
import IO
import That
main= do 
 outh <- openFile "tudin-G-H-C1.ghc" WriteMode; 
 hPutStrLn outh (acc "Hello, fa\unhbox \voidb at x \setbox \z@ \hbox {c}{\lineskiplimit -\maxdimen \unhbox \voidb at x \vtop {\baselineskip \z at skip \lineskip .25ex\everycr {}\tabskip \z at skip \halign {##\crcr \unhbox \z@ \crcr \hskip \hideskip \char 24\hskip \hideskip \crcr }}}ade!")

 hClose outh;
 outh <- openFile "tudin-G-H-C2.ghc" WriteMode; 
 hPutStrLn outh (show (fat 6))

 hClose outh;

As you can see, LaTeX sends its macro expansion to the Haskell file.  Another possibility is to change the classification of \ (reverse slash). Here is how to do it:


Now the reverse slash is a normal char. Of course, I need to change the classification of every accent, tilde, cedil, umlaut, etc. I cannot change the grave, because I need it to make the change itself. Users don't like this kind of solution. In any case, here are the programs with the characters modified (I will post a more complete library in my site; then I will add a few graphical functions so people can understand the problem). Compilation is as before:

1 --- C:\hastex>  latex tudin.tex
2 --- C:\hastex> runghc tudin.hs
3 --- C:\hastex> latex tudin.tex

It is possible to use pdflatex instead of latex. By the way, Haskell cannot print your name, since it has an acute i :-) It would be great if people could solve this problem.

% Store in file hask.ell
% Last change 2007-05-23 


  \csname newwrite\endcsname\outPort % Port name
  \immediate\openout\outPort \jobname.hs %
  \immediate\write\outPort{import H\jobname}%
  \immediate\write\outPort{import IO}%
  \immediate\write\outPort{main= do  }%

  \ifx\outPort\UNDEFINED \evalSetup\fi
  \global\advance\evalFilecount by 1
    {  outh <- openFile "\evalAuxFile.ghc" { WriteMode;} }%
   \ifeof0 \immediate\closein0 
   \else \input \evalAuxFile.ghc \fi}%

  \immediate\write\outPort{   hClose outh;}%
%end of file hask.ell

% Store in file  haskell.gen
% Last change 2007-05-23 


  \csname newwrite\endcsname\progPort 
  \immediate\openout\progPort H\jobname.hs %
  \immediate\write\progPort{module H\jobname}%

  \ifx\progPort\UNDEFINED \haskellSetup\fi%

%end of file haskell.gen

% File: tudin.tex


\title{Calling Haskell from \LaTeX}
\author{Philippos Apolinarius}


\input haskell.gen
\input hask.ell % load \eval 

\eval{ hPutStrLn outh "Hello, fa\\c cade!"

\eval{ hPutStrLn outh "Il est l\\`a bas!"

\eval{ hPutStrLn outh "Raison d' \\^etre!"

\eval{ hPutStrLn outh "Votre toast, je peux vous le rendre, Se\\~nor!"

\eval{ hPutStrLn outh (show (fat 6))

 fat n | n<1= 1
 fat n= n*fat(n-1)


--- On Sat, 10/24/09, Maurí­cio CA <mauricio.antunes at gmail.com> wrote:

From: Maurí­cio CA <mauricio.antunes at gmail.com>
Subject: [Haskell-cafe] Re: A 3 line program --> Reid, Don, Daniel
To: haskell-cafe at haskell.org
Received: Saturday, October 24, 2009, 8:28 PM


Doesn't the line below means everything to be interpreted will be
considered as latin1?


Unicode as UTF-8 won't fit here.

I would sugest transfering the problem to latex. Why not to print
'fa\c cade' instead of 'façade'? It's 7 bits and will never fail.


> Thank you for your help. I am sure that you are right as to the cause of the problem.  However, I do not know what I should do to solve it. The Haskell program is generated by LaTeX macros. (...)

Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

Looking for the perfect gift? Give the gift of Flickr! 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091024/f1c002bc/attachment.html

More information about the Haskell-Cafe mailing list