HTML to TeX simple converter tool.
- One javascript file
- Capable to run from your local disk
- No modules or any backend/framework needed
- around 7 kB (not minified)
- Supports base of standard output from Marked and Prism
- Template can be customized
- Part of bigger project that has been refactored to be independent
-
Demo implementation is a single HTML file to show you needed configuration to make it work.
- Scroll down and click Convert to TeX button
- Result will be shown in textarea under the button
- Copy button doesn't have any function and it is kept exactly as it is being produced by Prism library (manually copied here to demonstrate how does this case works)
-
HelpViewer integration source code: export handler and pre export preparation for image links collection. This code is executed when you will click on top right dropdown button (📥) and select TEX format.
Add reference to head section:
<script src="https://raw.githubusercontent.com/HelpViewer/HTMLToTeX/refs/heads/main/HTMLToTeX.js" type="text/javascript"></script>or copy this file to your local environment.
Call HTMLToTeX function with
parameters:
- parent - HTMLElement which contains all your HTML data which should be converted to TeX
- header - String which is used as document name (used on title page and in page headings)
- activeLanguage - language of your document (use en for default)
- config - Configuration values (object with key value string pairs)
- ctx - internal state context for single run (provide: { listStack: [], i_img: 0, i_svg: 0, embeds: new Map() } as default)
- listStack - ul/ol nesting sequence
- i_img - img tags found counter
- i_svg - svg tags found counter
- embeds - previously collected embedded objects (img, svg)
- document - base LaTeX document template (you need to create your own, no default here, consult demo)
to get result : array of :
- 0 - base template
- 1 - your HTML DOM converted to TeX
which must be processed like this:
result[0].replace('%DOC%', result[1]);to get complete TeX source code.
- Tool only generates TeX source code
- Tool focuses on using only the basic packages and functions of the TeX ecosystem
- La/TeX compilation process must be executed several times due to page numbering issues (usual behavior on TeX platform)
- Text formatting functions are used only to a basic extent (despite your HTML can be more rich in format)
- SVG file insertion is currently not working correctly (e.g.: Windows with MikTeX system)
Provide DIV with CSS class page-break:
<div class="page-break"></div>to spots where you would like to emit page break in TeX.
Provide exactly what is shown in the example here, without any content inside, because the content here is skipped during the conversion process.
- No managed packages or artifacts are planned to be released from this repository
- Work directly with the content of the main branch of the GitHub repository
- Repository is used with Git submodules in HelpViewer project