使用Haskell图表构建器解析错误

时间:2017-09-25 12:38:54

标签: haskell latex haskell-diagrams

我正在尝试将图表构建器包与LaTeX一起使用,以便生成图表。在教程here之后,我有一个名为test.tex的文件,其中包含以下内容:

\documentclass[10pt]{article}

\usepackage[backend=ps, extension=eps, outputdir=diagrams]{diagrams-latex}
\usepackage{graphicx}

\begin{document}
\begin{diagram}[width=300,height=200]
{-# LANGUAGE FlexibleContexts #-}
dia = circle 1 
\end{diagram}

\end{document}

我创建了一个名为diagrams的空目录并尝试编译,只是被告知在diagrams-builder-ps自动生成的文件中存在解析错误。

$ pdflatex --enable-write18 --shell-escape test.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.17 (TeX Live 2016) (preloaded format=pdflatex)
 \write18 enabled.
entering extended mode
(./test.tex
LaTeX2e <2016/03/31>
Babel <3.9r> and hyphenation patterns for 83 language(s) loaded.
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/size10.clo))
(/Users/nhalford/Library/texmf/tex/diagrams-latex.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/moreverb/moreverb.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/tools/verbatim.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/xkeyval/xkeyval.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkeyval.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkvutils.tex
(/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/keyval.tex))))
(/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2016/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ltxcmds.sty))))
No file test.aux.
(/usr/local/texlive/2016/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty)
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifpdf.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2016/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2016/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
Opening diagrams-latex stream diagrams/test-diagrams-latex-fig1.hs Error while compiling diagrams/test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58258-0.hs:3:20: error:
    parse error on input ‘-’



Package diagrams-latex Warning: Conversion of diagrams/test-diagrams-latex-fig1
.hs failed.


Package diagrams-latex Warning: Please convert diagrams/test-diagrams-latex-fig
1.hs manually.

(./test.aux) )
No pages of output.
Transcript written on test.log.

尝试直接在diagrams-builder-ps文件上运行diagrams-builder-cairo.hs时,我也遇到此错误:

$ cd diagrams
$ ls
test-diagrams-latex-fig1.hs
$ diagrams-builder-ps -w 300 -h 200 test-diagrams-latex-fig1.hs
Error while compiling test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58289-0.hs:3:20: error:
    parse error on input ‘-’

$ diagrams-builder-cairo -w 300 -h 200 test-diagrams-latex-fig1.hs
Error while compiling test-diagrams-latex-fig1.hs
/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58294-0.hs:3:20: error:
    parse error on input ‘-’

$ cat test-diagrams-latex-fig1.hs
{-# LANGUAGE FlexibleContexts #-}
dia = circle 1
$

不幸的是,系统会立即删除带有解析错误的临时.hs文件,因此我无法检查该文件以查看导致此问题的确切原因。

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

哦,我想我只是想出了什么一定是错的,虽然我不确定解决问题的最佳方法。关键是这一行:

/var/folders/2g/_6mplpfn4fl338wr3cj949440000gn/T/Diagram58289-0.hs:3:20: error:

请注意,临时文件的名称为Diagram58289-0.hsdiagrams-builder调用openTempFilesee here),然后使用生成的文件的基本名称作为模块的名称。因此Diagram58289-0.hs的内容必须如下所示:

{-# LANGUAGE FlexibleContexts #-}

module Diagram58289-0 where

dia = circle 1

问题是连字符在模块名称中无效,因此解析错误(当然,它位于第3行的第20列)。

虽然documentation for openTempFile表示创建的文件的名称格式为“fooXXX.ext,其中XXX是一个随机数字”,但显然这不是这里发生的事情。事实上,它看起来像behavior of openTempFile changed recently;现在它将始终包含连字符。我猜这种行为在base-4.10中发生了变化,所以对于任何使用GHC 8.2的人都会出现这种情况。

我有created an issue on the diagrams-builder issue tracker来跟踪这个问题。目前,一种解决方案是降级到GHC 8.0,但这可能不是一个非常有吸引力的选择。