diagrams-latex with diagrams-pgf?

139 views
Skip to first unread message

Ed Morehouse

unread,
Jul 11, 2015, 1:22:30 PM7/11/15
to diagrams...@googlegroups.com
Can anyone comment on what it would take to get diagrams-latex working with the diagrams-pgf backend?

I would like to try to transition from TikZ to Diagrams in most of my LaTeX documents, but need my diagram fonts (in particular math) to match the rest of the document and sometimes need transparency, making diagrams-postscript a poor choice.  I have previously tried and failed to get diagrams-cairo working on my system and would rather not go that route.

thanks,

-Ed

Brent Yorgey

unread,
Jul 11, 2015, 2:03:35 PM7/11/15
to Ed Morehouse, diagrams...@googlegroups.com

I actually already have this working. Later today I will take a look to see whether there are any commits I need to push etc. and send some instructions.

-bent


--
You received this message because you are subscribed to the Google Groups "diagrams-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diagrams-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brent Yorgey

unread,
Jul 11, 2015, 2:04:16 PM7/11/15
to Ed Morehouse, diagrams...@googlegroups.com

Heh, silly auto-correct.

-Brent

edward.m...@gmail.com

unread,
Jul 11, 2015, 2:25:49 PM7/11/15
to diagrams...@googlegroups.com, edward.m...@gmail.com
Wow, that's great, thanks!

-Ed

Brent Yorgey

unread,
Jul 11, 2015, 6:17:52 PM7/11/15
to edward.m...@gmail.com, diagrams...@googlegroups.com
OK, I reminded myself of what I had done and it's all checked in, but not yet released.  I should also update the diagrams-builder README.  In the meantime here's what you need to do to get it to work:

* Install the latest version of `diagrams-builder` from github, being sure to pass the -fpgf option to cabal install so it installs the builder executable for PGF (and make sure the resulting executable is on your path)
* Get the latest version of diagrams-latex.sty from the diagrams-builder repo:

https://github.com/diagrams/diagrams-builder/blob/master/latex/diagrams-latex.sty

* See https://github.com/diagrams/diagrams-doc/blob/master/doc/latex.rst  for instructions on how to use it.  The short version is that you pass an extra option 'input' to the diagrams-latex package which tells it to use \input instead of \includegraphics.

I have successfully gotten this to work, including text typeset by LaTeX embedded in diagrams, so it is definitely possible.  Let me know if you run into any difficulties.

-Brent

Edward Morehouse

unread,
Jul 11, 2015, 11:38:47 PM7/11/15
to Brent Yorgey, diagrams...@googlegroups.com
Hi Brent,

Sorry, but I'm super naive about Cabal. Can I do cabal install with a
package that's not in Hackage or do I need to do runhaskell Setup
instead? I searched around for a bit trying to figure it out but am
still confused. If it's not too much trouble, could you please give
either more explicit instructions or else a pointer to where I can learn
the right way to install Cabal packages from sources other than Hackage.

Thanks again, I'm really excited about diagramming my latex. =)

-Ed
> <mailto:diagrams-discu...@googlegroups.com>.

Daniel Bergey

unread,
Jul 12, 2015, 11:22:08 AM7/12/15
to Edward Morehouse, diagrams...@googlegroups.com
On 2015-07-12 at 03:38, Edward Morehouse <edward.m...@gmail.com> wrote:
> Hi Brent,
>
> Sorry, but I'm super naive about Cabal. Can I do cabal install with a
> package that's not in Hackage or do I need to do runhaskell Setup
> instead? I searched around for a bit trying to figure it out but am
> still confused. If it's not too much trouble, could you please give
> either more explicit instructions or else a pointer to where I can learn
> the right way to install Cabal packages from sources other than Hackage.

It's easy to cabal install a package not in Hackage. There are two
ways: You can run `cabal install` with no package name, from the
directory with the .cabal file. Or you can run `cabal install
<package-directory>/` where <package-directory> is a path to the code.
Cabal recognizes the trailing slash, and looks for a local project
rather than a package name on Hackage.

Daniel

Brent Yorgey

unread,
Jul 12, 2015, 4:15:54 PM7/12/15
to Daniel Bergey, Edward Morehouse, diagrams...@googlegroups.com
To be even more pedantic (also for the benefit of anyone else reading the mailing list), you could do something like this:

mkdir diagrams
cd diagrams
cabal sandbox init    # optional but recommended, builds everything in a sandbox
git clone http://github.com/diagrams/diagrams-builder builder
cabal install diagrams -fpgf builder/    #  the trailing / is important
cabal exec zsh    # now all invocations of ghc etc. will use the packages in the sandbox; type 'exit' to exit
export PATH=/path/to/diagrams/.cabal-sandbox/bin:$PATH   # use the diagrams-builder-pgf executable from the sandbox
wget https://raw.githubusercontent.com/diagrams/diagrams-builder/master/latex/diagrams-latex.sty   # then put this somewhere LaTeX can find it

Then continue by following the instructions at https://github.com/diagrams/diagrams-doc/blob/master/doc/latex.rst .

-Brent


Edward Morehouse

unread,
Jul 12, 2015, 5:32:24 PM7/12/15
to Brent Yorgey, Daniel Bergey, diagrams...@googlegroups.com
Thank you Brent and Daniel!

I am happy to report preliminary success. I was able to typeset a
document with a few simple diagrams, including text subsequently typeset
by LaTeX in math mode.

A couple quick comments regarding the instructions at

https://github.com/diagrams/diagrams-doc/blob/master/doc/latex.rst

In order to avoid:

LaTeX Error: Environment pgfpicture undefined.

I had to add to the LaTeX preamble:

\usepackage{pgf}

which is pretty obvious, but not mentioned. And when I tried to build
the circles example, GHC complained:

Illegal equational constraint V t ~ V2
(Use GADTs or TypeFamilies to permit this)
When checking that ‘foo’ has the inferred type

which was solved by following the compiler's recommendation.

Thanks again,

-Ed


On 2015-07-12 4:15 PM, Brent Yorgey wrote:
> To be even more pedantic (also for the benefit of anyone else reading
> the mailing list), you could do something like this:
>
> mkdir diagrams
> cd diagrams
> cabal sandbox init # optional but recommended, builds everything in a
> sandbox
> git clone http://github.com/diagrams/diagrams-builder builder
> cabal install diagrams -fpgf builder/ # the trailing / is important
> cabal exec zsh # now all invocations of ghc etc. will use the
> packages in the sandbox; type 'exit' to exit
> export PATH=/path/to/diagrams/.cabal-sandbox/bin:$PATH # use the
> diagrams-builder-pgf executable from the sandbox
> wget
> https://raw.githubusercontent.com/diagrams/diagrams-builder/master/latex/diagrams-latex.sty
> # then put this somewhere LaTeX can find it
>
> Then continue by following the instructions at
> https://github.com/diagrams/diagrams-doc/blob/master/doc/latex.rst .
>
> -Brent
>
>
> On Sun, Jul 12, 2015 at 11:22 AM Daniel Bergey <ber...@teallabs.org
> <mailto:ber...@teallabs.org>> wrote:
>
> On 2015-07-12 at 03:38, Edward Morehouse <edward.m...@gmail.com
> <mailto:edward.m...@gmail.com>> wrote:
> > Hi Brent,
> >
> > Sorry, but I'm super naive about Cabal. Can I do cabal install with a
> > package that's not in Hackage or do I need to do runhaskell Setup
> > instead? I searched around for a bit trying to figure it out but am
> > still confused. If it's not too much trouble, could you please give
> > either more explicit instructions or else a pointer to where I
> can learn
> > the right way to install Cabal packages from sources other than
> Hackage.
>
> It's easy to cabal install a package not in Hackage. There are two
> ways: You can run `cabal install` with no package name, from the
> directory with the .cabal file. Or you can run `cabal install
> <package-directory>/` where <package-directory> is a path to the code.
> Cabal recognizes the trailing slash, and looks for a local project
> rather than a package name on Hackage.
>
> Daniel
>
> --
> You received this message because you are subscribed to the Google
> Groups "diagrams-discuss" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to diagrams-discu...@googlegroups.com
> <mailto:diagrams-discuss%2Bunsu...@googlegroups.com>.

Edward Morehouse

unread,
Jul 13, 2015, 12:54:49 PM7/13/15
to diagrams...@googlegroups.com
So far this is working great, except that it mangles Unicode, which I
use liberally since XeTeX is my preferred TeX engine. Does anyone know
whether it is builder or the backend that is doing this and how
difficult it would be to change?

Just to mention, I have previously used the SVG backend (but without
builder) with Unicode text and it worked fine.

Also, can anyone comment on what is the best way for dealing with
Unicode text in Haskell, I've heard good things about Data.Text, but
haven't used it myself.

cheers,

-Ed

Brent Yorgey

unread,
Jul 13, 2015, 3:58:31 PM7/13/15
to Edward Morehouse, diagrams...@googlegroups.com
Ah, if it mangles Unicode then that is definitely a bug.  Can you give a simple example of something that does not work as you expect?  Offhand I have no idea where the error might be so having an example I could use to reproduce it would be helpful.

Yes, Data.Text is the gold standard for properly handling Unicode text in Haskell.  The Char type natively represents Unicode codepoints (not bytes), so in theory you can use String to work with Unicode text, but it does not properly handle things like searching for substrings, upper/lowercasing, etc. (because of things like combining characters vs precombined, special upper/lowercasing rules for some languages that can turn a single codepoint into multiple codepoints or vice versa, etc.) To properly handle all of that you should use Data.Text.

-Brent

--
You received this message because you are subscribed to the Google Groups "diagrams-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to diagrams-discu...@googlegroups.com.

Edward Morehouse

unread,
Jul 13, 2015, 5:09:39 PM7/13/15
to Brent Yorgey, diagrams...@googlegroups.com
There's a small example attached.

-Ed
> <mailto:diagrams-discuss%2Bunsu...@googlegroups.com>.
minimal.tex

chalmers.c...@gmail.com

unread,
Jul 13, 2015, 5:49:47 PM7/13/15
to diagrams...@googlegroups.com, edward.m...@gmail.com, byo...@gmail.com
This is my fault. I wasn't using uft8 encoding for these strings. I've uploaded the fix to Hackage. Hopefully this will fix your problem.

Edward Morehouse

unread,
Jul 22, 2015, 6:10:40 PM7/22/15
to chalmers.c...@gmail.com, diagrams...@googlegroups.com, byo...@gmail.com
Well, the behavior is pretty interesting now, but I can't understand
what it's doing. In the example that I sent last week, the "f : α → β"
in the math block within the diagram gets rendered as "f : ± ²". But if
I remove the space before the "α", or even just add more spaces, then it
renders correctly.

I reinstalled everything into a fresh sandbox to make sure that it
wasn't a versioning issue. Can anyone else confirm, or explain, this
behavior?

-Ed



On 2015-07-13 5:49 PM, chalmers.c...@gmail.com wrote:
> This is my fault. I wasn't using uft8 encoding for these strings. I've
> uploaded the fix to Hackage
> <http://hackage.haskell.org/package/diagrams-pgf-0.1.0.2>. Hopefully
> > <edward.m...@gmail.com <javascript:>
> <mailto:edward.m...@gmail.com <javascript:>>> wrote:
> >
> > So far this is working great, except that it mangles Unicode,
> which I
> > use liberally since XeTeX is my preferred TeX engine. Does
> anyone know
> > whether it is builder or the backend that is doing this and how
> > difficult it would be to change?
> >
> > Just to mention, I have previously used the SVG backend (but
> without
> > builder) with Unicode text and it worked fine.
> >
> > Also, can anyone comment on what is the best way for dealing
> with
> > Unicode text in Haskell, I've heard good things about
> Data.Text, but
> > haven't used it myself.
> >
> > cheers,
> >
> > -Ed
> >
> > --
> > You received this message because you are subscribed to the
> Google
> > Groups "diagrams-discuss" group.
> > To unsubscribe from this group and stop receiving emails from
> it,
> > send an email to diagrams-discu...@googlegroups.com
> <javascript:>

Christopher Chalmers

unread,
Jul 26, 2015, 6:26:30 PM7/26/15
to diagrams-discuss, chalmers.c...@gmail.com, byo...@gmail.com, edward.m...@gmail.com
Heh, I'm guessing this is due to the old version getting cached. diagrams-builder hashes the diagrams code and reuses previously rendered diagrams to speed up compile times. Unfortunately the hash doesn't consider package versions (although there is an issue do this), so you're getting the old render. This would explain why adding seemingly inconsequential space renders it correctly. Clearing the diagrams_cache folder and trying it again should fix it.

Edward Morehouse

unread,
Jul 27, 2015, 6:50:58 PM7/27/15
to Christopher Chalmers, diagrams-discuss, chalmers.c...@gmail.com, byo...@gmail.com
Ah, okay, now I think I understand what's going on. As a matter of
fact, I had already tried clearing the diagrams_cache folder, and it
didn't help. But now I see that the builder has also created a hidden
version, ".diagrams_cache", containing the output for (presumably) all
the diagrams I've been passing through it. Clearing this hidden cache
does, in fact, seem to solve my problem.

Thanks!

-Ed

On 2015-07-26 6:26 PM, Christopher Chalmers wrote:
> Heh, I'm guessing this is due to the old version getting cached.
> diagrams-builder hashes the diagrams code and reuses previously rendered
> diagrams to speed up compile times. Unfortunately the hash doesn't
> consider package versions (although there is an issue
> <https://github.com/diagrams/diagrams-builder/issues/6> do this), so
Reply all
Reply to author
Forward
0 new messages