Nimble Toolbox

Convert HTML to LaTeX

Paste HTML code, or text copied straight from a web page or a document, and the LaTeX appears as you type. Headings, emphasis, lists, tables, and links come through; colours, fonts, and layout do not.

How to use it#

  1. Paste HTML code into the box, or copy text from a web page or a document and paste it, and the HTML behind it goes in.
  2. Choose a whole file that compiles as it is, or the body alone to paste into a document of your own.
  3. Pick the margins, what a top heading becomes, how code blocks are written, and whether headings are numbered.
  4. Read the notes for anything LaTeX cannot take as written, then copy the LaTeX or download the .tex file.

What comes through, and what stays behind#

The structure of the page comes through: h1 to h6 become sections and subsections, strong and em become \textbf and \emph, lists become itemize and enumerate, tables become a tabular, links become \href, and pre blocks become verbatim or listings. Text a word processor made bold or italic with a style rather than a tag, as Google Docs does, keeps its emphasis too.

How the page looks does not. Colours, fonts, sizes, margins, columns, and anything else set with CSS has no place in LaTeX, which lays out the page itself from the document class. Scripts, styles, and forms are left out, and a tag with no LaTeX form, such as a div or a span, gives up its text and nothing else.

Pasting from a web page or a document#

Copying from a browser or a word processor puts two copies on the clipboard: the plain text, and the HTML behind it. Pasted here, the HTML goes in, so a heading arrives as a heading and a link keeps its address. Pasting from a plain text editor brings no HTML, and the page says so.

The HTML is read without being shown or run, so nothing in it can do anything, and no picture it names is fetched. A picture becomes an \includegraphics of its address, which the notes point out: LaTeX cannot fetch it, so save it beside the .tex file first.

Every character escaped#

Text on a page is text, so every character LaTeX treats as a command is escaped: "50% off" prints as written instead of starting a comment, and a backslash prints as a backslash. That includes text that looks like LaTeX, such as "$x^2$" or "\alpha", since on a web page it is only words, and a reference like "[1]" stays as written.

To work in LaTeX by hand first, the HTML to markdown converter gives the same document as markdown to edit, and the markdown to LaTeX converter takes it from there, LaTeX commands and math included.

Frequently asked questions#

Is my HTML uploaded anywhere?

#

No. The conversion happens in this tab, and nothing you paste is sent to a server or shown on this page.

Why are the colours and fonts gone?

#

LaTeX lays out the page itself from the document class, so styling set with CSS has nowhere to go. The structure is kept: headings, emphasis, lists, tables, links, and code.

What should a heading become?

#

Section suits an article, where the page title is the largest heading in a document. Chapter suits a book or a thesis, and switches the file to the report class. Title turns the first h1 into the title of the whole piece, and the h2 headings into sections.

Verbatim or listings for code?

#

Verbatim prints a pre block in a typewriter font exactly as written. Listings adds a frame and wraps long lines, and highlights keywords when the block names a language listings knows, such as Python or C.

Can I turn the LaTeX into a PDF?

#

Yes. Choose Whole file, then paste the result into LaTeX to PDF, which compiles it in your browser.

Does it convert a Word or Google Docs document?

#

Yes, by copying. Select the text in the document, copy it, and paste it here: the HTML the editor puts on the clipboard carries the headings, lists, tables, and links across. Bold and italic set as styles are kept too.

Can I paste straight from a web page or a document?

#

Yes. Copy the part you want and paste it into the box. The formatting behind the text goes in as HTML, so headings, links, and lists come across. HTML code copied from an editor goes in as the code. Code copied along with the page around it, such as a tutorial with its headings, could be either, so it goes in as the code, and the page asks whether to convert that code or the page's own HTML. A paste with no formatting at all, as from a plain text editor, goes in as plain text and the page says so.

Can I convert a saved web page?

#

Yes. Open the .html file in a text editor, copy all of it, and paste it here. Everything outside the page body, such as its head and scripts, is left out.