mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
295 stars 28 forks source link

DVI → SVG lost default LaTeX font on MikTeX #186

Closed VincentTam closed 2 years ago

VincentTam commented 2 years ago

Background

I'm using the same version as in https://github.com/mgieseki/dvisvgm/issues/184, and the MWE from https://github.com/MiKTeX/miktex/issues/1112#issuecomment-1159117316

Problem

  1. I compiled with latex.
  2. I used dvisvgm without -P.
  3. The resulting SVG doesn't have LaTeX's default font.
$ latex 220617-fill
This is pdfTeX, Version 3.141592653-2.6-1.40.24 (MiKTeX 22.3) (preloaded format=latex.fmt)
 restricted \write18 enabled.
entering extended mode
(220617-fill.tex
LaTeX2e <2022-06-01> pre-release-0 (develop 2022-6-17 branch)
L3 programming layer <2022-06-02>
(C:\Users\sere\AppData\Local\Programs\MiKTeX\tex/latex/standalone\standalone.cl
s
Document Class: standalone 2018/03/26 v1.3a Class to compile TeX sub-files stan
dalone
...
[1] [2] (220617-fill.aux) )
Output written on 220617-fill.dvi (2 pages, 19180 bytes).
Transcript written on 220617-fill.log.

$ dvisvgm -o foobar.svg 220617-fill
pre-processing DVI file (format version 2)
processing page 1
  graphic size: 213.73187pt x 173.012041pt (75.118161mm x 60.806778mm)
  output written to foobar.svg
1 of 2 pages converted in 0.165 seconds

foobar

Expected output:

A SVG that looks like the following (with transparent background).

image

I saw that GhostScript is in the dependencies. However, with MikTeX, the command for GS is mgs instead of gs. Does dvisvgm recognise this?

mgieseki commented 2 years ago

I guess, the SVG file contains the correct font data but your SVG viewer can't render it properly. That's a common issue. If you call dvisvgm with option --no-fonts, which replaces all text elements by paths, or --font-format=woff, the SVG should render correctly. There's also some information about this in the FAQ.

I saw that GhostScript is in the dependencies. However, with MikTeX, the command for GS is mgs instead of gs. Does dvisvgm recognise this?

Yes, if dvisvgm was built for MiKTeX, it also looks for mgsdll64.dll or mgsdll32.dll.

VincentTam commented 2 years ago

Thx very much with your response & link to FAQ. I finally got the exacted output. :tada:

dvisvgm pgfplots

VincentTam commented 2 years ago

For personal reference only.

foobar

here's the result run with --no-fonts.

image

it's OK after uploading through GitHub.

However, the SVG created by --font-format=woff that I had uploaded in my prev msg would be distorted after GitHub upload.

image

VincentTam commented 2 years ago

what surprises me is that the good svg takes less spaces than the bad one:

$ curl -L https://user-images.githubusercontent.com/5748535/174452553-cd79f0ba-972d-4286-9288-e6526e065204.svg > gd.svg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13116  100 13116    0     0   130k      0 --:--:-- --:--:-- --:--:--  132k
$ curl -L https://user-images.githubusercontent.com/5748535/174452321-b78ee8d9-371b-43c4-9e4e-f4ed26a864d8.svg > bd.svg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13362  100 13362    0     0   189k      0 --:--:-- --:--:-- --:--:--  189k
$ ls -l {gd,bd}.svg
-rw-r--r-- 1 xxxx 197609 13362 juin  18 21:03 bd.svg
-rw-r--r-- 1 xxxx 197609 13116 juin  18 21:03 gd.svg
mgieseki commented 2 years ago

Great to hear that you were able to fix the problem.

However, the SVG created by --font-format=woff that I had uploaded in my prev msg would be distorted after GitHub upload.

That's a security measure of the web browser which prevents loading the embedded font data if you load the SVG from a server.

What surprises me is that the good svg takes less spaces than the bad one:

The base64 encodings of the embedded WOFF fonts are quite lengthy and enlarge the file a bit. In contrast, the path variant without any fonts is more compact. You can reduce the file size even more by restricting the number of decimal places used in the SVG, e.g. with --precision=2 and by using relative path commands (option --relative).

VincentTam commented 2 years ago

I appreciate your help. I used -d 2 and the file size is reduced by 30-40%.

foobar

$ dvisvgm --no-fonts -R -d 2 -o foobar.svg 220617-fill.dvi
pre-processing DVI file (format version 2)
processing page 1
  graphic size: 213.73pt x 173.01pt (75.12mm x 60.81mm)
  output written to foobar.svg
1 of 2 pages converted in 0.119 seconds

$ curl -L https://user-images.githubusercontent.com/5748535/174454795-c09be583-7748-43db-a6a7-1936b16d775a.svg > precision2.svg
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8266  100  8266    0     0   115k      0 --:--:-- --:--:-- --:--:--  115k

$ ls -l precision2.svg 
-rw-r--r-- 1 sere 197609 8266 juin  18 21:39 precision2.svg