Skip to content

Instantly share code, notes, and snippets.

@tobywf
Last active April 26, 2024 10:14
Show Gist options
  • Save tobywf/aeeeee63053aaaa841b4032963406684 to your computer and use it in GitHub Desktop.
Save tobywf/aeeeee63053aaaa841b4032963406684 to your computer and use it in GitHub Desktop.
Build dvisvgm and kpathsea on macOS
#!/bin/bash
set -xeuo pipefail
IFS=$'\n\t'
PREFIX="${1:-/usr/local/dvisvgm}"
TEX="$(kpsewhich -var SELFAUTOLOC)"
echo "$PREFIX, $TEX"
brew install automake freetype ghostscript potrace
# download the sources
mkdir -p "$PREFIX/source/texk"
cd "$PREFIX/source/"
# see https://www.tug.org/texlive/svn/
rsync -av --exclude=.svn tug.org::tldevsrc/Build/source/build-aux .
rsync -av --exclude=.svn tug.org::tldevsrc/Build/source/texk/kpathsea texk/
git clone git@github.com:mgieseki/dvisvgm.git
# compile kpathsea
cd texk/kpathsea
# patch SELFAUTOLOC
perl -0777 -i.bak \
-pe 's|(kpathsea_selfdir \(kpathsea kpse, const_string argv0\)\n{)|$1\n return xstrdup("'"$TEX"'");\n|g' \
progname.c
./configure --prefix="$PREFIX/"
make
make install
# compile dvisvgm
cd ../../dvisvgm
./autogen.sh
CPPFLAGS="-I$PREFIX/include/" LDFLAGS="-L$PREFIX/lib/" ./configure --prefix="$PREFIX/"
make
make check
make install
@lisp3r
Copy link

lisp3r commented Feb 25, 2019

macOS Mojave 10.14.2

It took me make a few additional things to make script works:

  1. Install Broti (configure: ... No package 'libbrotlienc' found)
  2. Install woff2 (configure: ... No package 'libwoff2enc' found)
  3. Change git clone git@github.com:mgieseki/dvisvgm.git to git clone https://github.com/mgieseki/dvisvgm.git

And script has worked well. Thank you!

@jovton
Copy link

jovton commented May 5, 2019

Your script actually helped my to build and install it on Linux (LFS) too! I could not get kpathsea installed from the tex live sources (texk-7.2). I had segmentation fault build errors. By analyzing this script, it helped me get the directory structure ready to install both dvisvgm and kpathsea. Thank you!

@annacnev
Copy link

annacnev commented Nov 19, 2019

^to nowaday's comment above you don't need to manually install Brotli or woff2, they are already bundled in dvisvgm. To build them and statically link them you have to do:

./configure --enable-bundled-libs instead of ./configure

Also, with this script I was getting error:
kpsewhich: option `-var' is ambiguous

but it was helpful in getting the directory structure right for installing dvisvgm and Kpathsea so thank you!

@tobywf
Copy link
Author

tobywf commented Nov 19, 2019

Awesome, glad it helps! That's great tip. I think the WOFF stuff was added shortly after I originally published this in April 2017. Hopefully I'll get some time to re-run this with the latest sources.

@maximechoulika
Copy link

maximechoulika commented Jan 6, 2020

For kpsewhich: option '-var' is ambiguous , just replace -var with -var-value, and it works.

@iamtekeste
Copy link

Thank you @tobywf for this script and @Talasta @Nowaday for the fixes too.

@wtroughton
Copy link

The perl regex fails due to unmatched left brace. Falling back to an older version of perl before 5.24 should work.

@SterlingHooten
Copy link

SterlingHooten commented Nov 19, 2021

The perl regex fails due to unmatched left brace. Falling back to an older version of perl before 5.24 should work.

Escaping the left open brace '{' with a backslash \ works with perl 5.34 on macos 11.2.3
-pe 's|(kpathsea_selfdir \(kpathsea kpse, const_string argv0\)\n\{)|$1\n return xstrdup("'"$TEX"'");\n|g' \

@jasoneveleth
Copy link

jasoneveleth commented Feb 5, 2022

I found that this wouldn't work unless I put the binary at $(kpsewhich -var-value SELFAUTOLOC) and then made a symbolic link to it.

@AdelleBernal
Copy link

I got this :(¨


+ IFS='
	'
+ PREFIX=/usr/local/dvisvgm
++ kpsewhich -var SELFAUTOLOC
kpsewhich: option `-var' is ambiguous
+ TEX=

@AdelleBernal
Copy link

-var-value

It worked!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment