*! version 1.1.0 30mar2026

Title

tomarkstat -- Convert Markdown from tohtml to markstat .stmd

Syntax

Basic syntax

tomarkstat filename.md [, options]

save(stubname|filename) path for the output .stmd; default is same folder and basename as input

replace overwrite an existing output file

filename.md is required and must be a Markdown file with extension .md (typically clean markdown
produced by tohtml with cleanmd()). Enclose the path in double quotes if it contains spaces.

Description

tomarkstat takes cleaned Markdown ({.md}) from tohtml (or similar) and converts it to
Stata Markdown ({.stmd}) for use with markstat using to render dynamic documents in HTML, PDF, Word,
and other formats.

Suggested workflow:

1. Mark locations in your do-file with ishere, run the job, and obtain a Stata log (.log) with markers.

2. Run tohtml (for example with cleanmd()) to produce a clean {.md} file.

3. Run tomarkstat on that {.md} to obtain an {.stmd} file.

4. Run markstat using basename[, markstat_options] to build the final document.

The output begins with two fixed header lines recognized by markstat. For fenced code blocks, the
first ``` on odd-indexed fence lines is rewritten as ```s so markstat treats the block as
Stata code.

Options

save(stubname|filename) sets the {.stmd} output path. If no extension is given, .stmd is appended;
if an extension is given it must be .stmd or the command issues an error. When omitted, the default is
.stmd in the same directory as filename.md with the same base name.

replace allows overwriting an existing output file; without it, an error is issued if the target file
already exists.

Remarks

In Mata, the command roughly applies the following line-wise transformations (details may change with the
source code):

• Lines starting with ```: on fence lines with odd index, the opening ``` becomes ```s
(to delimit Stata code cells for markstat).

• Lines related to internal handling of isheredisplay (after removing all spaces from the line) are
dropped.

• Two fixed header lines are inserted at the top so the file is treated as a Stata Markdown document.

Examples

From tohtml clean markdown to stmd

. tohtml mylog.smcl, cleanmd(myreport_clean.md) replace

. tomarkstat myreport_clean.md, replace

Then, with markstat installed:

. markstat using myreport_clean, strict

Custom output path

. tomarkstat "E:\work\out_clean.md", save("E:\work\article.stmd") replace

Stub only (appends .stmd)

. tomarkstat out_clean.md, save(../report/main) replace

Authors

Stata_tohtml team; tools for the ishere–tohtml workflow.