![]() |
Converters for Markdown | ![]() |
TeXmacs reads and writes Markdown, the plain text format of the README files, of many note taking programs and of the answers of AI assistants. A file with the suffix .md (or .markdown, .mkd) opens as a document; a document is written as Markdown with File\(\rightarrow\)Export\(\rightarrow\)Markdown and read with File\(\rightarrow\)Import\(\rightarrow\)Markdown, and Edit\(\rightarrow\)Copy to\(\rightarrow\)Markdown and Edit\(\rightarrow\)Paste from\(\rightarrow\)Markdown do the same for a piece of a document. A text is never taken for Markdown by its contents: to paste one, use Edit\(\rightarrow\)Paste from\(\rightarrow\)Markdown, or make it the default with Tools\(\rightarrow\)Miscellaneous\(\rightarrow\)Import selections as.
The dialect is CommonMark with the extensions of GitHub (tables, struck through text, task lists, addresses which are links) and those of Pandoc which matter for scientific texts: formulas, footnotes and a header with the title.
The formulas are LaTeX, $x^2$ in the text and
$$
\int_0^1 x^2 \,dx = \frac{1}{3}
$$ |
on lines of their own; \(x^2\) and \[x^2\] are read too. They go through the converters for LaTeX in both directions, so that a formula which is read becomes a formula of TeXmacs which can be edited, and the formulas which are written are those which MathJax and KaTeX display, on GitHub for instance. As for Pandoc, a dollar opens a formula only when no space follows it, and closes one only when no space precedes it and no digit follows it: a price of $5 and $6 has no formula. A formula which is a single symbol, such as an arrow, is written in LaTeX too, as $\rightarrow$, and is a formula again when it is read.
A file which is opened is a document of the style markdown: text without serifs, headings without numbers, and a few macros which keep what Markdown says and the standard tags do not. Such a document is written as the file it was read from: what you did not touch keeps its meaning, and what Markdown cannot say in two ways keeps its text; what you edit is written anew.
The six levels are section, subsection, subsubsection, paragraph, subparagraph and md-h6, whatever the first one of the file is, and a file has no title of its own.
The lines of a YAML header are kept in md-metadata, one md-meta with a key and its value for each of them (and without key for a line which has none, or which is not written key: value: an item of a list, a comment, a line with other spaces). Keys can be edited, added and removed, and are written in their order; a line typed in the header is written as it is, or as a comment when YAML has no such line. Whatever the header holds between its two lines --- is kept, if each of its lines is a key, a comment, an item of a list or an indented line, and one of them at least is a key: a heading between two rules stays a heading. A header without key is written as paragraphs, and an empty one is not written.
They are in md-source (in a paragraph) or md-block-source (on lines of their own), with the text of the file for them: \(x\) stays \(x\), a table keeps the widths of its columns, and Html which TeXmacs does not understand, a comment for instance, is kept and shown as a flag. As soon as the formula, the table or the text is edited, it is written by TeXmacs. So are the tabs, which are displayed as spaces (in code, each line with tabs keeps them until it is edited), the definitions of links to which nothing refers (the comments [//]: # (text) among them), and the definitions of footnotes which the text does not use. The definitions of the links and footnotes which a table uses are kept too, and a mark of a footnote in a table keeps its label.
The lists whose items start with -, * and + are itemize-minus, itemize-dot and itemize-arrow, and a list with blank lines between its items is in md-loose.
The words after the fence are kept by md-fence when the language is not one of those which TeXmacs highlights, or is not written as TeXmacs writes it (c for cpp). A tab which starts a line of code stays a tab, as in a formula, in Html and in the header.
An image with a description or a title is in md-image; an image alone with a description and no title is a figure with this caption, as below.
A footnote whose label is not its number is md-footnote, with this label, and md-footnote-text marks the place where its text is written when this is not the end of the file, in a quotation or a list as well. The text of a footnote is at its first mark; the other marks of the same footnote, a mark inside the text of a footnote and a mark without footnote are kept as they are written. When two footnotes have the same label, the second one gets another label as it is written.
The text which these macros keep is not displayed, and is written as it is: a document of this style which someone else wrote may write text you do not see into the Markdown file, as specific may. The other formats display the macros and leave out what they keep.
What Markdown writes in several ways is written in one when it is none of the above: the lines of a paragraph are joined (the spaces and tabs which start them are not text), a heading with a line under it starts with #, code is between ‘‘‘, a rule is ***, emphasis is written with stars, a link through a definition is written with its address, and a character written as & or after a backslash is written as itself unless it would be taken for markup. The file which is written says the same, and is written as itself from then on.
With Edit\(\rightarrow\)Preferences\(\rightarrow\)Convert\(\rightarrow\)Markdown a file is read as a document of the style generic instead, with the title and the sections which TeXmacs displays for it; text which is pasted is always read so, since it may go into any document.
The lines which start with #, and those underlined with === or ---, are sections, subsections and so on. When a text has a single heading of the first level, at its start, it is the title of the document and the other headings move up.
A YAML header between two lines --- at the start of the file gives the title, the authors (author, one or a list), the date and the abstract. Pasted text has no header: its lines --- are rules.
Emphasized, strong and struck through text, code, links, images, line breaks, the entities of Html. The quotes and the apostrophes of typography stay these characters, also in code and in addresses, and are written back as they were.
An image alone in its paragraph, with a description, , is a figure whose caption is this description (or its title, , when it has one), as for Pandoc. An image inside a text is the image alone. An image may have a size, with the attributes of Pandoc, {width=50%}, or with the tag of Html, <img src="file.png" width="300">; a tag img with other attributes, as a style, stays Html.
A link with a title, [text](address "title"), is a hlink*, which keeps the title.
With bullets or numbers, nested, with several paragraphs in an item; the task lists (- [ ] and - [x]) get a box as their bullet.
Between lines of three backquotes or indented by four spaces; a tab which starts a line goes to the next column which is a multiple of four, as CommonMark says, and the columns of it which the indentation of the code or of a list takes are spaces. The language which follows the backquotes selects the environment, python-code, scm-code, cpp-code…, and verbatim-code otherwise.
With the alignment of their columns and their first row in bold. A table too wide for the page gets its width and its cells are broken into lines.
A footnote does not hold other footnotes: a mark inside the text of a footnote stays as it is written. Quotations and lists inside each other are read down to a hundred levels, and are text beyond.
The tags of Html inside the text are read by the converter for Html. A block of Html ends at a blank line, but a comment, pre, script, style and textarea go on to their end.
A document is first expanded as for Html: the numbers of the sections, of the theorems and of the equations, the references and the citations are those which TeXmacs displays (update the document first, with Document\(\rightarrow\)Update\(\rightarrow\)All). A paragraph is one line, and only the characters which Markdown would take for markup are escaped.
A title alone is the heading of the first level, and the sections are of the second one. With authors or a date, they are written in a YAML header, unless Edit\(\rightarrow\)Preferences\(\rightarrow\)Convert\(\rightarrow\)Markdown says otherwise; the abstract follows as a paragraph.
Their name and number in bold, then their body; a table is followed by its caption.
Formulas in LaTeX, with \tag for the numbered equations.
The tables of GitHub, whose first row is the header. Their cells are single lines: the paragraphs of a cell are joined.
The title of an hlink* is written with the link.
A figure which is a single image is written as this image, with the caption as its description: . The other figures are followed by their caption. An image with a width or a height is written as the tag img of Html, since Markdown has no sizes: in pixels, or in percents for a part of the width of the paragraph.
The images which are files keep their name. Those which are inside the document are saved beside the file which is written: with name.md, the files name-1.png, name-2.png and so on.
An underlined text is emphasized and a key of the keyboard is code. A subscript or a superscript made of digits and signs is written with the characters which Unicode has for them (as in H2O or x2). The other ones and the marked text are written with the tags of Html, which most programs display (Edit\(\rightarrow\)Preferences\(\rightarrow\)Convert\(\rightarrow\)Markdown turns this off: they are then plain text). Colors, fonts, sizes and alignments are dropped, and so are the drawings made with TeXmacs.
Outside the style markdown, a file which is written and read again is not always the document it was. The sizes of the images come back in pixels or as parts of the paragraph, whatever their unit was, and a height which is neither is dropped. The headings start again at the first level, so that the sections of a document with chapters are subsections afterwards. An address which stands in the text is a link when it is read, and braces which follow an image are read as its size.
To write something only into the Markdown file, Format\(\rightarrow\)Specific\(\rightarrow\)Html is used for Markdown too.