fletcher / fletcher/MultiMarkdown-6

Inline SVG math in HTML output.

Open
#154 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
678
Forks
94
PR merge metrics
No merged PRs in 30d

Description

It'd be super great if MultiMarkdown had an option to produce inline SVG's for its math so one doesn't have to include a JS-based math renderer on one's page.

This can be accomplished with `dvisvgm --no-fonts`, which is included with [several Tex distros](https://dvisvgm.de/Links/). If it's helpful, below is a functioning Ruby script for replacing `math` spans from MultiMarkdown HTML with inline SVGs.

```ruby
USAGE = 'Converts math in ... to inline SVG. Usage: $ ruby math_to_svg.rb file.html'

path = ARGV[0] || (STDERR.puts USAGE; exit 1)

`mkdir -p tmp`

new_html =
File.read(path).gsub(/\\\(([\s\S]*?)\\\)<\/span>/) do |match_str|
latex_str = $1.gsub("<", "<").gsub(">", ">")
latex_doc = %Q|\\documentclass{standalone}\n\\usepackage{amsmath}\n\\begin{document}\n$#{latex_str}$\n\\end{document}|

File.write("tmp/tmp.tex", latex_doc)

if system("pdflatex -output-format=dvi -interaction=nonstopmode -output-directory=tmp tmp/tmp.tex")
if system("dvisvgm --output=tmp/tmp.svg --no-fonts tmp/tmp.dvi")
File.read("tmp/tmp.svg")
else
match_str
end
else
match_str
end
end

`rm -r tmp`

File.write(path, new_html)
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the supplied math_to_svg.rb script and its pdflatex and dvisvgm workflow, then locate the existing MultiMarkdown HTML math-output entry point. The work is done when an option produces inline SVG math without a JavaScript renderer, while preserving the existing output behavior when the option is not enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
latex, ruby
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.