Directory macros/latex/contrib/codemwe
The code-MWE LaTeX package based on fancyvrb and tcolorbox
The codemwe package is a LaTeX package for typesetting code examples together with their results and for generating MWE (Minimal Working Example) source files. It is developed with Expl3 and builds on fancyvrb, tcolorbox and related packages. Code can be typeset either by the original fancyvrb scheme, or with syntax highlighting provided by the minted package (enabled with the minted option, which requires -shell-escape).
The codemwe package provides four environments: the example environment typesets an example code box and its result box side by side (or stacked in the vertical mode) and automatically generates an independently compilable MWE file; the example* environment is the vertical-mode variant; the texcode environment typesets a code box only, without numbering or compilation; and the ccode environment is preset for C code, showing a code box only and generating a .c source file. Besides the environments, the \codemweset macro sets global default options, \codemweNewBox registers user-defined box environments, \codemweNewLang registers new language varieties for the transition phrases and structural comment words, and \codemweNewBackend registers new code backends (e.g. Python) beyond the built-in LaTeX and C backends.
At the same time, the codemwe package offers customization options for examples, including the typesetting mode, numbering and labels, result figures, result box, code backends, line numbers, syntax highlighting, etc. These can be configured through package options, environment options, or the \codemweset macro.
For further details and examples, please refer to the manual (in Chinese/English).
Contributing
- gitee repository: (1). repository: code-mwe (2). Issues and PR: issue or pull request.
基于fancyvrb与tcolorbox的代码MWE排版LaTeX宏包
codemwe是一个用Expl3开发、基于fancyvrb、tcolorbox等宏包的LaTeX宏包,用于排版示例代码及其运行结果,并自动生成可独立编译的MWE(Minimal Working Example)源文件。示例代码默认按原样排版,也可以使用minted选项改用minted宏包实现语法高亮(此时需以-shell-escape选项编译文档)。
codemwe宏包提供了四个环境:example环境以水平模式(左代码框、右结果框)或垂直模式(上代码框、下结果框)排版示例代码及其编译结果,并自动生成可独立编译的MWE文件;example*环境是垂直模式变体;texcode环境仅排版一个代码框,不编号、不编译示例代码;ccode环境面向C语言代码预置了相应选项,仅显示代码框并生成.c源文件。同时,宏包还提供\codemweset命令用于设置全局默认选项,\codemweNewBox命令用于注册用户自定义的盒子环境,\codemweNewLang命令用于注册过渡语与结构注释词的新语种,\codemweNewBackend命令用于注册内置LaTeX与C后端之外的新代码后端(如Python)。
同时,codemwe宏包还为示例排版提供了排版模式、编号与引用、结果图片、结果框、代码后端、行号、语法高亮等功能设置选项,可以通过宏包选项、环境选项对其进行设置,也可以通过\codemweset命令实现全局设置。
可以通过阅读宏包手册(中英文双语)以了解该宏包更多的使用细节和使用样例。
参与贡献
- gitee仓库: (1). 仓库地址: code-mwe (2). Issues and PR: issue or pull request.
Copyright and Licence
Copyright (C) 2026 by Nan Geng <nangeng@nwafu.edu.cn> ----------------------------------------------------------------------
This work may be distributed and/or modified under the conditions of the LaTeX Project Public License, either version 1.3c of this license or (at your option) any later version. This version of this license is in http://www.latex-project.org/lppl/lppl-1-3c.txt and the latest version of this license is in http://www.latex-project.org/lppl.txt and version 1.3 or later is part of all distributions of LaTeX version 2005/12/01 or later.
This work has the LPPL maintenance status "maintained".
The Current Maintainer of this work is Nan Geng.
This package consists of codemwe.sty, codemwe.tex and README.md(this file),
and the derived files codemwe.pdf.
Download the contents of this package in one zip archive (811.1k).
Codemwe – Typeset code with a result box and generate MWE files
This package typesets example code together with its compiled result and writes out a minimal, independently compilable source file for every example. It is written in expl3 and built on tcolorbox, fancyvrb and graphicx.
The package was written for manuals, teaching material and package documentation, where the same snippet has to appear three times: as displayed code, as a result, and as a standalone file that the reader can compile. codemwe keeps these three representations in step from a single source.
| Package | Codemwe |
| Bug tracker | |
| Repository | |
| Version | 1.1.0 |
| Licenses | The LaTeX Project Public License 1.3c |
| Copyright | 2026 Nan Geng |
| Maintainer | Nan Geng |
| Topics | Debug support Listing Verbatim |