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

\catcode`\\=11

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 

\newcount\evalFilecount
\evalFilecount=0

{\gdef\evalSetup{%
  \csname newwrite\endcsname\outPort % Port name
  \immediate\openout\outPort \jobname.hs %
  \newlinechar=`\^^M% 
  \immediate\write\outPort{import H\jobname}%
   \newlinechar=`\^^M% 
  \immediate\write\outPort{import IO}%
   \newlinechar=`\^^M% 
  \immediate\write\outPort{main= do  }%
  \newlinechar=`\^^M% 
}%
}

\newcommand{\eval}{\begingroup
  \ifx\outPort\UNDEFINED \evalSetup\fi
  \global\advance\evalFilecount by 1
  \edef\evalAuxFile{\jobname-G-H-C\the\evalFilecount}%
  \immediate\write\outPort
    {  outh <- openFile "\evalAuxFile.ghc" { WriteMode;} }%
  {\immediate\openin0=\evalAuxFile.ghc
   \ifeof0 \immediate\closein0 
   \else \input \evalAuxFile.ghc \fi}%
  \catcode`\^^M=12 
  \catcode`\\=11
  \catcode`\~=11
  \catcode`\'=11
  \catcode`\`=11
  \catcode`\^=11
  \evalBody 
 }

\newcommand{\evalBody}[1]{%
  \immediate\write\outPort{#1}%
  \immediate\write\outPort{   hClose outh;}%
  \endgroup
  }
%end of file hask.ell




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

\newcount\evalFilecount
\evalFilecount=0

{\gdef\haskellSetup{%
  \csname newwrite\endcsname\progPort 
  \immediate\openout\progPort H\jobname.hs %
  \immediate\write\progPort{module H\jobname}%
  \immediate\write\progPort{where}%
  \newlinechar=`\^^M% 
  \newlinechar=`\^^M%
}%
}

\newcommand{\haskell}{\begingroup
  \ifx\progPort\UNDEFINED \haskellSetup\fi%
  \catcode`\^^M=12 
  \haskellGen
 }

\newcommand{\haskellGen}[1]{%
  \immediate\write\progPort{#1}%
  \endgroup
  }
%end of file haskell.gen



% File: tudin.tex
\documentclass[12pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[brazil]{babel}
\usepackage{makeidx}
\usepackage{wrapfig}
\usepackage{pictexwd}

\newcommand{\cc}{\c{c}}

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

\begin{document}
\maketitle

\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))
}

\haskell{
 fat n | n<1= 1
 fat n= n*fat(n-1)
}
\end{document}








 

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

Philippos,

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

  \usepackage[latin1]{inputenc}

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.

Best,
Maurício

> 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
http://www.haskell.org/mailman/listinfo/haskell-cafe



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

http://www.flickr.com/gift/
-------------- 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