Last update: 13.03.2007
Contents
13.03.2007
- Beta version of SVGfrags!
- pl: Na razie usuwam polską dokumentację, bo się trochę zdezaktualizowała, a naprawdę są ciekawsze rzeczy od jej pisania.
7.03.2007
Better, and I hope more obvious, command line parsing. Now output file name or output directory can be set. For example:
dvi2svg.py file.dvi # output: file.svg dvi2svg.py file.dvi test.svg # output: test.svg dvi2svg.py file.dvi dir/ # output: dir/file.svg dvi2svg.py file.dvi dir/test.svg # output: dir/test.svgNew option --always-number — affects on output file name: append page number to output name even if one page is converted.
Option --paper-size=bbox accepts four numbers, for left, right, top and bottom margin, i.e. --paper-size=bbox:left,right,top,bottom
6.03.2007
Switch --paper-size accept new keyword bbox (see description of this option for details) — paper size is set to bounding box of page.
Sample: famous Einstein equation
new option --verbose
4.03.2007
- added support for mftrace utility — automatically conversion of METAFONT fonts is available
3.03.2007
- generate a bit smaller SVG files
- new options --no-fontforge and --no-fnt2meta that disables use of FontForge/fnt2meta
- option --paper-size accepts value "query" — all known names & sizes are printed
2.03.2007
- Improved .PFA/.PFB searching
- Another bug fixed
1.03.2007
Some bugs were fixed, thanks for help to R (Chandra) Chandrasekhar.
16.10.2006
If pydvi2svg can't find SVG but Type1 fonts (PFA or PFB) are available in your TeX installation then automatically use FontForge (or fnt2meta) to converts such font.
fnt2meta.c is a small utility that reads font file and prints glyph outlines (need FreeType2). Compilation:
gcc -O2 -lfreetype fnt2meta.c -o fnt2metaor:
gcc -O2 `freetype-config --libs` `freetype-config --cflags` -o fnt2meta fnt2meta.c
15.10.2006
New methods to determine encoding (see --enc-methods switch)
This is another DVI to SVG converter (and is written in Python).
When I was started to write this program I just want to export mathematical expressions. But since DVI is just a set of commands that puts characters and move magic current point around a page, pydvi2svg is able to convert any kind of document.
There is partial support for color.sty specials.
Why another converter? Because programs I've checked — if they worked of course — embeded SVG font in the file. This is not supported by most SVG viewer/editor programs, including Inkscape that I use often. Because of that pydvi2svg embeds glifs as a paths and simply links to them. It works perfectly. Tested with gqview, rsvg, Inkscape, Firefox 1.5-2.0 and Opera 9.
Article borrowed from English Wikipedia about DVI file format. Font face used: Computer Modern.
Article borrowed from polish Wikipedia about Antykwa Półtawskiego — the original polish font face. Of course if you open SVG you will see this font "in action".
Wikipedia articles are licensed under GNU GFDL license.
Following archives are needed:
If you have them, then:
$ tar -xjf pydvi2svg.tar.bz2 $ tar -xjf fonts.tar.bz2
After correct installation directory tree should looks as follow:
pydvi2svg
|
+- cache - empty dir
+- conv - dvi2svg program files
+- frags - SVGfrags program files
+- enc - set of *.enc files
+- fonts
|
+- cm - set of *.svg files
Now you can create symbolic link to pydvi2svg.py (and/or svgfrags.py) in some directory listed from $PATH, for example:
sudo ln -sf <full path to script>/dvi2svg.py /usr/local/bin/
If realpath utility is present in your system, then:
sudo ln -sf `realpath pydvi2svg/dvi2svg.py` /usr/local/bin
dvi2svg.py [OPTION] file.dvi [target SVG/dir]
For example:
dvi2svg.py file.dvi # output: file.svg dvi2svg.py file.dvi test.svg # output: test.svg dvi2svg.py file.dvi dir/ # output: dir/file.svg dvi2svg.py file.dvi dir/test.svg # output: dir/test.svg
You can set as many input-output pairs as you want, for example:
dvi2svg.py file1.dvi file2.dvi output2.svg file3.dvi outputdir
Options:
List of document pages or page ranges to convert. List's element are separated by colons. Examples:
--pages 1,2,3,4,7 # convert pages 1, 2, 3, 4 and 7 --pages 1-4,7 # above shorter --pages 7- # convert all pages starting from 7th --pages -10 # convert pages 1-10
By default all pages are converted.
Choose methods used to determine font encoding:
Default value: cache,tfm,afm
Override (or set) encoding of selected fonts. Elements are separated with colons, and has format font name:encoding name. For example:
--enc cmr12:ot1,pltt12:pltt
Change default scale of document
Default value: 1.0
--paper-size [value]
value:
page format name, like A4, B3, etc. (see Wikipedia); for example --paper-size A4, --paper-size=B5
string query — all known names are printed and program exits
string bbox — paper size is set to bounding box of page; additionaly margin around bbox can be set:
- bbox:margin — all margin equal
- bbox:marginx,marginy — margin left & right equal marginx, margin top & bottom equal marginy
- bbox:margin_left,margin_right,margin_top,margin_bottom
for example --paper-size=bbox:10, --paper-size bbox:5,20, --paper-size=bbox:10,20,30,40
Default value: A4
The easiest way is to convert your own fonts with Fontforge assistance. SVG font have to be placed in fonts directory or its subdirectory.
Fontforge is able to read most vector font formats---in a TeX installation we usually find Type1 fonts (PFB or PFA). If there is just Metafont source, you still can convert font: Fontforge use autotrace or potrace to trace glyph's vector outlines.
Before you create font (Generate font...) assure that glyph's names are not changed (option No Rename set).
If you use other utility, make sure that output SVG fits following rules:
SVG have to get following structure:
<font>
<glyph name="..." d="..."/>
<glyph name="..." d="..."/>
...
</font>
or
<font>
<glyph name="...">
<path d="..."/>
</glyph>
<glyph name="...">
<path d="..."/>
</glyph>
...
</font>
(Of course these rules are not fixed and I'm able to change them, but have never met SVG fonts with different structure).
Usually it means that encoding of certain font is not correct. Try to change it with command line option --enc: look in enc subdirectory or locate other .enc files in your TeX installation.
If you find correct encoding you can change pydvi2svg settings permanently. You have to update file enc/file.info; single line has format:
font_name encoding_name designsize
Here is a sample:
pltt12 pltt 12.000000
pydvi2svg tries to find TFM files and read encoding name (it tries AFM files too, but it is not well tested). But if SVG font has been converted from, for example, Type1 format its' encoding may be different.
For example TFM file that describe font pltt12 claims that encoding is "TeX typewriter text", i.e. texnansi. But since this font was converted from PFB we have to a look into some .map file, and than will notice that TeX applies encoding file called pltt.enc (so, we must set encoding pltt).
Likewise CM fonts may have encoding OT1 instead of T1.
You have to check which *.enc describe reported encoding. Files are placed in directory enc and somewhere in your TeX installation tree. If you find adequate encoding, then update file enc/enc.info (and of course drop me a line).
SVGfrags is utility build on top of pydvi2svg, that includes pieces of TeX/LaTeX expressions into existing SVG file. It works similar to well known psfrags LaTeX package, but has some additional features.
SVGfrags is distributed with pydvi2svg, see Installation section.
Replacement rules have to be defined in separate file, and must follow this simple syntax:
SVG target => TeX expression [additional options] % the same comments style as in (La)TeX
You can see detailed syntax, or better read next sections and take a look at example.
SVG target could be (case A):
Additionally SVG target could refer to rectangular area, where TeX expression is placed (case B):
TeX expression could be:
Place TeX expression relative to SVG target object.
Syntax:
position ::= px ["," py]
By default py = 1.0 and px = 0.0 (case B) or px = inherit (case A).
Arguments px and py define point inside rectangle (bounding box of TeX expression, and also in target rectangle in case B). For example px = 0.5, py = 0.5 is center point; px = 0.0, py = 1.0 — left lower corner, and so on.
px and py can be:
Some useful constants are also defined:
Point inside bbox of TeX expression is calculated and then expression is moved to make this point and reference equal.
In this case px can have value inherit (default), then px gets value (if possible) from SVG attribute text-anchor or from CSS style string. These values are start = 0.0, middle = 0.5 and end = 1.0 (see SVG spec for more info about text-anchor).
Points inside bbox of TeX expression and target rectangle are calculated and then expression is moved to make these points equal.
For example if px = 0.5, py = 0.5 then TeX expression is centered.
Additional margins around bounding box of TeX expression; applied before scaling. Syntax:
Uniform or nonuniform scale of TeX expression.
Syntax:
scale: "fit" | (sx ["," sy])
Value fit is suitable only in case B — TeX expression is uniformly scaled to fill a target rectangle.
Scale factor sx/sy values:
SVGfrags accepts also following pydvi2svg options:
"TeX & LaTeX" => "\TeX\ \& \LaTeX"
scale: 4
"$\sin x + \cos x = 1$" => this
scale: 3
"equation2" => "$f(x) = \frac{x^3 - 5}{x^2 + 4} \cdot \frac{1}{x}$"
scale: 3
"left" => this
scale: uniform, length 20
"center" => this
scale: uniform, length 20
"right" => this
scale: uniform, length 20
"top" => "top"
position: left, top
scale: uniform, length 20
"center2" => "center"
position: left, center
scale: uniform, length 20
"bottom" => "bottom"
position: left, bottom
scale: uniform, length 20
#title => "\LaTeX/\TeX\ \& \texttt{SVGfrags}"
position: center, center
margin: 1
scale: fit
#scaletowidth => "\[P(t) = \sum_{i=0}^n p_i B_i^n (t)\]"
scale: width(this)
#scaletoheight => "\[\frac{1}{\frac{1}{\frac{1}{x}}}\]"
position: 0.7
scale: uniform, height(this)
#nonuniform => "\[\frac{1}{x^2 + 1} + \frac{\sin x}{\log_2 x}\]"
scale: width(this), height(this)
#settowidth => "$\sin x$"
scale: width(#scaletowidth), height(#nonuniform)
% eof



Please send to author any remarks, bugs, patches, questions, etc.:
Wojciech Muła, wojciech_mula@poczta.onet.pl