Skip to content

Commit

Permalink
Adds option to fix SVGs. (3b1b#23)
Browse files Browse the repository at this point in the history
Adds a new option to the constants.py, TEX_FIX_SVG. This is False by
default, but can be enabled to use cairosvg to fix SVGs automatically.

This allows the use of some fonts and shapes that might otherwise be
problematic.
  • Loading branch information
xfbs authored and eulertour committed Oct 18, 2018
1 parent 4ffed92 commit 7ec6046
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def init_directories(config):
os.makedirs(folder)

TEX_USE_CTEX = False
TEX_FIX_SVG = False
TEX_TEXT_TO_REPLACE = "YourTextHere"
TEMPLATE_TEX_FILE = os.path.join(THIS_DIR, "tex_template.tex" if not TEX_USE_CTEX
else "ctex_template.tex")
Expand Down
14 changes: 14 additions & 0 deletions utils/tex_file_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from constants import TEX_DIR
from constants import TEX_TEXT_TO_REPLACE
from constants import TEX_USE_CTEX
from constants import TEX_FIX_SVG


def tex_hash(expression, template_tex_file):
Expand Down Expand Up @@ -105,6 +106,18 @@ def dvi_to_svg(dvi_file, regen_if_exists=False, remove_rectangles=False):
get_null()
]
os.system(" ".join(commands))

if TEX_FIX_SVG:
commands = [
"cairosvg",
result,
"-f",
"svg",
"-o",
result
]
os.system(" ".join(commands))

if remove_rectangles:
with open(result, "r+") as f:
lines = f.readlines()
Expand All @@ -114,4 +127,5 @@ def dvi_to_svg(dvi_file, regen_if_exists=False, remove_rectangles=False):
f.write(line)
f.truncate()
f.close()

return result

0 comments on commit 7ec6046

Please sign in to comment.