Daniel-Diaz / HaTeX

The Haskell LaTeX library.
BSD 3-Clause "New" or "Revised" License
199 stars 46 forks source link

Support for Haskell graphics libraries? #116

Open bbarker opened 6 years ago

bbarker commented 6 years ago

I'm curious if it is possible to employ other Haskell libraries, particularly graphics libraries (e.g. https://archives.haskell.org/projects.haskell.org/diagrams/ ) in some fashion (maybe this has already been done, if so, apologies).

I could actually see this mode of usage as being maybe a nice way to get away from things like TikZ, but maybe I'm being too hopeful - ultimately it is still probably desirable to support TikZ and PGF

leftaroundabout commented 6 years ago

There used to be an attempt of writing a TikZ backend for diagrams, but AFAIK it never really worked and is unsupported.

Practically speaking, I find the sensible thing is to render the diagrams to .pdf using the Cairo backend, and then includegraphics those files in the HaTeX document. This works quite smoothly and can be done inline if using HaTeX as LaTeXT IO.

leftaroundabout commented 6 years ago

(There's also a backend straight to .pdf, but this isn't up to date either.)

leftaroundabout commented 6 years ago

Concerning this subject, I wonder if it would be worthwhile to add some tooling to HaTeX that would make such including of automatically-generated files easier. I've implemented something like that in the yeamer library, which handles all the filename disambiguation behind the scenes and allows simply writing

import Presentation.Yeamer
import qualified Diagrams.Prelude as Dia
import qualified Diagrams.Backend.Cairo as Dia

myPresentation = do
     ...
     "other content"
     imageFromDiagram (
        Dia.circle 1 & Dia.lc Dia.red
      )
     "more other content"
     ...
...

imageFromDiagram :: Dia.Diagram Dia.Cairo -> Presentation
imageFromDiagram dia = imageFromFileSupplier "png"
           $ \tgtFile -> Dia.renderCairo tgtFile
                           (Dia.mkSizeSpec $ Just 640 Dia.^& Just 480) dia