[IN DEVELOPMENT]
$ npm install html-to-latexConverting html text:
import { convertText } from 'html-to-latex';
const html = `<p>Styled <b>Text</b></p>`;
const tex = await convertText(html);
console.log(tex)
//\documentclass{article}
//
//\begin{document}
//
//Styled \textbf{Text}
//
//\end{document}Converting html file:
import { convertFile } from 'html-to-latex';
const html = 'filePath.html';
await convertFile(html);Returns: Promise<string>
Converts the input htmlText to a valid latex string.
Type: string
Type: object
Type: boolean
Default: true
CLI Options: -ib or --ignore-breaks
Instead of replacing <br/> with //, ending the line, a simple space character is inserted instead.
Type: boolean
Default: false
CLI Options: -dm or --prefer-dollar-inline-math
Replace \( and \) with $.
Type: boolean
Default: false
CLI Options: -swe or --skip-wrapping-equations
Is an equation is defined in a p tag without any other content besides that equation, it will automatically be wrapped in \[ and \].
Type: boolean
Default: false
CLI Options: -dw or --include-document-wrapper
Adds a latex document wrapper around the converted text. This is required to have a valid latex file:
\documentclass{article}
\begin{document}
%...converted text
\end{document}Type: string
Default: article
CLI Options: -dc or --document-class
If a document wrapper is added, the document class will be set.
\documentclass{article}
%...Type: string[]
Default: []*
CLI Options: -ip or --include-packages
If the document wrapper is added, a list of used packages will be set.
\documentclass{article}
\usepackage{packagename}
\begin{document}
%...converted text
\end{document}*If nothing is specified, the list of includes packages will be inferred from the html:
| Tag | Added Package |
|---|---|
| \cfrac | amsmath |
| \img | graphicx |
| \therefore | amssymb |
Type: string
Default: undefined
CLI Options: -t or --title
If a document wrapper is added, the title will be set.
\documentclass{article}
\title{Altered Carbon}
\begin{document}
%...converted text
\end{document}Type: string
Default: undefined
CLI Options: -a or --author
If a document wrapper is added, the author will be set.
\documentclass{article}
\author{Takashi Kovacs}
\begin{document}
%...converted text
\end{document}Type: boolean
Default: false
CLI Options: -d or --incude-date
If a document wrapper is added, the current date will be set.
\documentclass{article}
\date{\today}
\begin{document}
%...converted text
\end{document}Type: string
Default: process.cwd
CLI Options: -cdr or --compilation-dir
If any images need to be downloaded for the latex compilation, they will be places in a 'images' subdirectory inside this directory.
Type: boolean
Default: true
CLI Options: -ain or --autogen-image-names
To avoid any weird file names, image files that are downloaded are automatically given a random Id with the extension of the original file. This can be turned off by passing a false value.
Type: string
Default: undefined
CLI Options: -iw or --image-width
Allows you to set a image width. This would be in the form normally accepted by latex such as: 2cm
Type: string
Default: undefined
CLI Options: -ih or --image-height
Allows you to set a image height. This would be in the form normally accepted by latex such as: 2cm
Type: boolean
Default: undefined
CLI Options: -kar or --keep-aspect-ratio
Allows you to maintain the aspect ratio of the image. This also requires either the image width property or image height property to be set.
Type: boolean
Default: false
CLI Options: --debug
Prints error messages when they occur such as when an image cannot be found at the given url.
CLI: available (see options for cli option names)
Returns: Promise
Converts the input file to a valid latex file.
Type: string
CLI Option: Positional, or -ifp
Path of html file
Type: object
All options included in .... and
includeDocumentWrapper option is defaulted to true for this function, as it would make more sense to do so
Type: string
Default: filepath (The input file path)
CLI Option: -ofp or --output-file-path
The output filepath of the converted file. By default it will overwrite the input file.
The same arguments are valid for the cli. The cli is exposed under html-to-latex executable and has the functions: convert-file and convert-text. Run html-to-latex --help for more information.
Instead designate new sections/paragraphs using the proper html tag such as a <p>