0

I am working on a configuration of the latex build process to use with Anki for compiling cards with latex content. I have some eps figures I want to include on some of my cards. The latest Anki version uses pdflatex which can't handle eps images. I have added the epstopdf to my list of packages and I have ghostscript installed, but I am getting error indicating that ghostscript cannot be opened for piped input. Is there something I can add to the build config to force epstopdf to find ghostscript?

I am able to convert the eps file manually from the command line:

epstopdf --debug /Images/commontriangles.eps commontriangles.pdf

I am on OSX Catalina.

This is what I get when I try which gs:

/usr/local/bin/gs

Here is the error:

Error executing ⁨pdflatex⁩.
Generated file: ⁨/var/folders/v_/5s080r992cvfltv_256bmxyr0000gp/T/anki_temp/tmp.tex⁩
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 \write18 enabled.
entering extended mode
(./tmp.tex
LaTeX2e <2020-02-02> patch level 5
L3 programming layer <2020-03-06>
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2020/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/jknapltx/mathrsfs.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/changepage/changepage.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2020/texmf-dist/tex/generic/iftex/ifvtex.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/iftex/iftex.sty)))
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)
(/usr/local/texlive/2020/texmf-dist/tex/latex/graphics-def/pdftex.def)))
(/usr/local/texlive/2020/texmf-dist/tex/latex/epstopdf-pkg/epstopdf.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/grfext/grfext.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty))
 (/usr/local/texlive/2020/texmf-dist/tex/latex/kvoptions/kvoptions.sty
(/usr/local/texlive/2020/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/local/texlive/2020/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty))
(/usr/local/texlive/2020/texmf-dist/tex/latex/pdftexcmds/pdftexcmds.sty)
(/usr/local/texlive/2020/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/local/texlive/2020/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)))
(/usr/local/texlive/2020/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def)
(./tmp.aux)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/local/texlive/2020/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
)epstopdf ($Id: epstopdf.pl 48681 2018-09-16 23:03:58Z karl $) 2.28
!!! Error: Cannot open Ghostscript for piped input: gs -q -dSAFER -dNOPAUSE -dBATCH -dCompatibilityLevel=1.5 -sDEVICE=pdfwrite -sOutputFile=/Images/commontriangles-eps-converted-to.pdf -dPDFSETTINGS#/prepress -dMaxSubsetPct=100 -dSubsetFonts=true -dEmbedAllFonts=true -dAutoRotatePages#/None - -c quit
system returned with code 512

Underfull \hbox (badness 10000) in paragraph at lines 14--15

Underfull \hbox (badness 10000) in paragraph at lines 14--15

Underfull \hbox (badness 10000) in paragraph at lines 17--18

! Package pdftex.def Error: File `/Images/commontriangles-eps -converted-to.pdf' not found: using draft setting.

See the pdftex.def package documentation for explanation. Type H <return> for immediate help. ...

l.23 \includegraphics{commontriangles.eps}

(/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/umsa.fd) (/usr/local/texlive/2020/texmf-dist/tex/latex/amsfonts/umsb.fd) (/usr/local/texlive/2020/texmf-dist/tex/latex/jknapltx/ursfs.fd) [1{/usr/local/ texlive/2020/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./tmp.aux) ) (see the transcript file for additional information)</usr/local/texlive/2020/te xmf-dist/fonts/type1/public/amsfonts/cm/cmbx9.pfb></usr/local/texlive/2020/texm f-dist/fonts/type1/public/amsfonts/cm/cmmi9.pfb></usr/local/texlive/2020/texmf- dist/fonts/type1/public/amsfonts/cm/cmr7.pfb></usr/local/texlive/2020/texmf-dis t/fonts/type1/public/amsfonts/cm/cmr9.pfb></usr/local/texlive/2020/texmf-dist/f onts/type1/public/amsfonts/cm/cmtt9.pfb> Output written on tmp.pdf (1 page, 53488 bytes). Transcript written on tmp.log.

Here is my build config:

{
    "pngCommands": [
        [
            "pdflatex",
            "--shell-escape",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "dvipng",
            "-D",
            "200",
            "-T",
            "tight",
            "tmp.dvi",
            "-o",
            "tmp.png"
        ]
    ],
    "svgCommands": [
        [
            "pdflatex",
            "--shell-escape",
            "-interaction=nonstopmode",
            "tmp.tex"
        ],
        [
            "dvisvgm",
            "--no-fonts",
            "-Z",
            "2",
            "tmp.dvi",
            "-o",
            "tmp.svg"
        ]
    ]
}

Here are the packages I am using on the card:

\documentclass[10pt,letterpaper]{article}
\usepackage{amssymb,amsmath,amsfonts,mathrsfs,changepage}
\usepackage[letterpaper,pass]{geometry}
\usepackage{graphicx}
\usepackage{epstopdf}
\graphicspath{ {/Images/} }
\pagestyle{empty}
\setlength{\parindent}{0in}
\DeclareMathOperator{\sech}{sech}
\DeclareMathOperator{\csch}{csch}
\begin{document} 
Selena
  • 195
  • If you are using texlive (not mactex) on mac, you have to install gs manually, through brew or any other way. – Syvshc Mar 01 '22 at 04:58
  • Your PATH environment variable seems different in your terminal (which gs) and in your session (used by Anki)... – Paul Gaborit Mar 01 '22 at 06:52
  • I do have gs installed manually, but my Mac came with another gs intallation too. How do I change the PATH environment variable for the Anki session to point to the gs which is installed by homebrew? – Selena Mar 01 '22 at 14:22
  • I uninstalled the other ghostscript, but Anki still isn't finding the brew-installed version. I can't figure out how to set PATH for gui APPs on Mac. There are a lot of people who ask about this, but it seems that some of the tried and true methods no longer work for newer OSX versions -- I have Catalina 10.15. I don't understand why this is so hard to do. Isn't there a way to use the build process Add-On to specify the location of the Ghostscript installation? – Selena Mar 01 '22 at 18:17

1 Answers1

0

So, there were a couple things going on here, but I will post the solution to the problem of Anki not finding my Ghostscript installation. Apparently, GUI apps launched from the Finder do not have the same value for the PATH environment variable that the terminal window has. So, the bash/zsh files that one normally uses to set PATH don't work for GUI Apps.

My Ghostscript installation is in /usr/local/bin/gs which wasn't present in the PATH for GUI apps on my system.

I found the solution here: https://stackoverflow.com/questions/55648312/mac-os-x-mojave-set-environment-variable-permanently in this answer specifically:

https://stackoverflow.com/a/58164730/2200733

There are other solutions to this problem that work for older version of OSX which were removed in later versions. My system is Catalina, 10.15.7. This solution worked for me and it persisted after a reboot.

I am copying and pasting the entire solution here:

Step 1: go to your $HOME/Library/LaunchAgents directory and create setenv.MY_VAR.plist file with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  <plist version="1.0">
  <dict>
  <key>Label</key>
  <string>setenv.MY_VAR</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/launchctl</string>
    <string>setenv</string>
    <string>MY_VAR</string>
    <string>SOME_VALUE_FOR_MY_VAR</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>

Pay attention that your file name and entries in the file match.

STEP 2: Run launchctl load ~/Library/LaunchAgents/setenv.MY_VAR.plist or - restart the system.

STEP 3: Restart your Terminal app.

STEP 4: Check if the var is there: env. It should give you: MY_VAR=SOME_VALUE_FOR_MY_VAR.

If you want to do more changes, first do launchctl unload... than launchctl load... again.

This is per user setting. If you want to set for all users, try doing the same in /Library/LaunchAgents.

The other issue with my setup is that pdflatex does not produce dvi files. So, dvipng is not the appropriate program to use for converting the intermediate result to a png file. Anyway, the fix for that issue is posted here on an old question of mine:

Anki 2.1 + Latex + Graphicx and including eps images: How to configure Anki so that I can include eps images with graphicx

Selena
  • 195