*! version 1.0.0 18jan2026

Title

tohtml -- Convert Stata log files to HTML reports

Syntax

Basic usage

tohtml filename|directory
[, options]

Output options
cleanmd(filename) specify output path for cleaned markdown file

html(filename) generate HTML file from cleaned markdown

replace overwrite existing output files

Style options
css(filename|githubstyle) specify CSS file or use GitHub style

Path options
rpath(directory) specify local path of resource files

wpath(url) specify web path (URL) for resource files

Cleaning modes
clean keep only headings, images, and tables

cleancode(dofile) replace log code with code from do-file

Figure options
width(string) set default width for images and tables

height(string) set default height for images and tables

zoom(string) set default zoom level for images

Description

tohtml is specifically designed to work hand-in-hand with ishere, forming a unified workflow
embodied by the phrase: everything is here: from do to html. This design philosophy emphasizes
a minimalist approach to reproducible research—where "is here" corresponds to the ishere command
(marking where elements belong), and "to html" corresponds to the tohtml command (converting marked
logs into polished reports).

The core principle is simple: everything you need for your analysis lives in one place—your do-file.
You mark locations with ishere, run your analysis, and tohtml transforms the log into a
professional HTML report. No external tools, no manual editing, no copy-pasting—just a streamlined path
from code to publication-ready output.

tohtml converts Stata log files containing ishere markers into formatted HTML reports.
The command can process a single log file or a directory containing multiple table and figure files. The latter gathers all table and figure files in the directory in a HTML.

tohtml provides the following main functions:

1. Clean log files: Removes Stata log control characters and extraneous output to produce clean Markdown files.

2. Process markers: Recognizes and processes ishere markers in log files, correctly formatting code blocks, headings, figures, and tables.

3. Generate HTML: Converts cleaned Markdown to HTML with customizable or preset CSS styles.

4. Path management: Supports resource file path replacement for generating portable reports.

5. Multiple modes: Supports standard mode, minimal mode (clean), and code merging mode (cleancode).

Options

Output options

cleanmd(filename) specifies the output path for the cleaned Markdown file. If not specified,
"_clean" will be appended to the input filename.

html(filename) converts the cleaned Markdown to HTML after processing.
Requires the markdown command to be installed.

replace overwrites existing output files. If this option is not specified and files exist,
the command will error.

Style options

css(filename|githubstyle) applies CSS styling to the generated HTML file. You can specify:

- Path to a custom CSS file

- githubstyle to use the built-in GitHub-style CSS

Using this option requires the html() option. The CSS file will be copied to a css
subdirectory in the HTML file's location.

Path options

rpath(directory) specifies the local path of resource files (images, tables, etc.).
This path will be replaced with the path specified in wpath(). Used for generating portable reports.

wpath(url) specifies the target path for resource files, typically a relative path (e.g., "./") or URL.
In the generated Markdown/HTML, rpath() will be replaced with this path.

Cleaning modes

clean activates minimal cleaning mode, keeping only headings starting with #, <img> tags,
<iframe> tags, and content within ishere text blocks. Removes all code and output.

cleancode(dofile) activates code merging mode. Uses the original code from the specified
do-file to replace code in the log file. The do-file must contain ishere markers to indicate
the positions of figures, tables, and other elements.

This mode is suitable when you want to display clean code (from do-file) alongside
execution results (from log file) in the report.

Figure options

width(string) sets the default width for all images and tables. Only effective when processing a directory.

height(string) sets the default height for all images and tables. Only effective when processing a directory.

zoom(string) sets the default zoom level for all images. Only effective when processing a directory.

Examples

Basic usage: Convert log file to Markdown

. tohtml "analysis.md", replace

Generate both Markdown and HTML

. tohtml "analysis.md", html("analysis.html") replace

Use GitHub style

. tohtml "analysis.md", html("analysis.html") css(githubstyle) replace

Use custom CSS

. tohtml "analysis.md", html("analysis.html") css("mystyle.css") replace

Specify output file names

. tohtml "analysis.md", cleanmd("report.md") html("report.html") replace

Path replacement: Generate portable report

. tohtml "analysis.md", html("report.html") ///

rpath("C:/Users/myname/analysis/output") wpath("./") replace

Minimal mode: Keep only headings and figures/tables

. tohtml "analysis.md", clean replace

Code merging mode: Use code from do-file

. tohtml "analysis.md", cleancode("analysis.do") html("report.html") replace

Process entire directory

. tohtml "output/", html("report.html") zoom(80%) replace

Complete workflow example

1. Create a do-file with ishere markers

. * ---- analysis.do ----

. log using "analysis.smcl", replace

. ishere # Data Analysis Report

.

. ishere ## Data Description

. ishere

. sysuse auto, clear

. describe

. summarize price mpg weight

. ishere

.

. ishere ## Regression Analysis

. ishere

. regress price mpg weight

. ishere

.

. ishere ## Visualization

. scatter price mpg

. graph export "scatter.png", replace

. ishere fig using "scatter.png", zoom(80%)

.

. log close

2. Translate SMCL log to Markdown

. translate analysis.smcl analysis.md, translator(smcl2log) replace

3. Use tohtml to generate HTML report

. tohtml "analysis.md", html("report.html") css(githubstyle) replace

Remarks

Mathematical formulas: When using the css(githubstyle) option, tohtml automatically
injects the MathJax library, enabling LaTeX mathematical formulas in Markdown. Use $...$ for inline formulas
and $$...$$ for display formulas.

File paths: All backslashes in file paths are automatically converted to forward slashes for cross-platform compatibility.

Processing directories: When the input argument is a directory rather than a file, tohtml automatically
scans for all HTML files starting with "table" and all image files starting with "figure", generating a
temporary Markdown file containing these resources.

Dependencies: Generating HTML requires Stata's markdown command. Install via:

. ssc install moremata

Author

Kerry Du

School of Management

Xiamen University

kerrydu@xmu.edu.cn

Huanyu Jia

School of Business

Zhengzhou University

jiahuanyu@zzu.edu.cn

See also

Help: ishere, markdown, log, translate