Reference

Contents

Index

MinimalWorkingExamples.@mweMacro
@mwe begin
    code
end [venue=:gh] [temp=true] [newprocess=true] [manifest=false]
    [advertise=nothing] [versioninfo=nothing] [preview=nothing]
    [packagespecs=PackageSpec[]] [manifest_path=nothing] [verbose=false]
    [julia_args=""] [plot_dir="MWEPlots"]

Generate a Minimal Working Example (MWE) formatted as Markdown, then copy it to the clipboard.

The code is rendered as a copy-pasteable Julia script with the value of each statement shown as a #> comment, alongside any print/logging output. Assignments and definitions (function, struct, module, etc.) are not echoed.

Keyword arguments

  • venue=:gh: output format — :gh for GitHub-Flavored Markdown (default), :discord for Discord (same as :gh but the advertisement note uses Discord's -# subtext syntax instead of <sup>), :slack for Slack (strips the language identifier from the code fence).
  • temp=true: create a temporary isolated environment and auto-add packages from using/import. When false, code runs in the current environment without auto-adding packages (to avoid polluting the user's project).
  • newprocess=true: run the MWE in a fresh Julia process; startup files are disabled to ensure reproducibility. If newprocess=false, the MWE runs in the current session. If also temp=true, a temporary project is activated for the execution and then restored.
  • manifest=false: append the Manifest.toml in a collapsible <details> block.
  • advertise=nothing: append a footer noting the date, this package, and Julia version used. If nothing (the default), this is false for :slack and true otherwise.
  • versioninfo=nothing: whether to append a collapsible "Environment" block showing the output of versioninfo(). If nothing (the default), this is true for :gh and false otherwise.
  • preview=nothing: which viewer shows the rendered result (see preview) — :editor (the host editor's viewer panel), :browser, or false (don't preview). If nothing (the default), this is false in non-interactive sessions, otherwise :editor when an editor viewer panel is available and :browser otherwise.
  • packagespecs=PackageSpec[]: vector of Pkg.PackageSpecs for packages that need a specific version, git revision, URL, or local path.
  • manifest_path=nothing: path to an existing Manifest.toml to use as-is. Mutually exclusive with packagespecs.
  • verbose=false: if true, show Pkg output (downloads, resolver messages) during environment setup.
  • julia_args="": extra command-line flags passed through to the isolated Julia process, e.g. "-t 4" or "--check-bounds=no". Only valid when newprocess=true.
  • plot_dir="MWEPlots": directory in which plots produced by the code are saved as PNGs. A visible **Insert plot here: ...** placeholder marks each plot's position in the Markdown. End a line with ; to suppress capture for that expression.
Note

The code block is rebuilt from its parsed AST, so comments and exact formatting are not preserved in the output. Use mwe if you need to preserve your code's formatting and comments.

Tip

The defaults above (except packagespecs and manifest_path) can be changed persistently with set_defaults!.

Examples

@mwe begin
    using Statistics
    x = [1, 2, 3, 4, 5]
    mean(x)
end versioninfo=false

Produces (copied to clipboard):

```julia
using Statistics
x = [1, 2, 3, 4, 5]
mean(x)
#> 3.0
```

<sup>Created on <date> with [MinimalWorkingExamples v<pkg-version>](https://github.com/BjarkeHautop/MinimalWorkingExamples.jl) using Julia <version></sup>

Pin a package to a specific version:

using Pkg
@mwe begin
    using Example
    Example.hello("World")
end packagespecs=[PackageSpec(name="Example", version="0.5.3")]
source
MinimalWorkingExamples.mweFunction
mwe([code]; kwargs...)

Function form of @mwe. Accepts code as a plain string. If code is omitted, reads Julia source from the clipboard.

Keyword arguments

Accepts the same keyword arguments (with the same defaults) as @mwe.

Examples

# Run code already copied to the clipboard:
mwe()

# Format for Slack:
mwe(; venue=:slack)

# Run an explicit string:
mwe("""
using Statistics
mean([1, 2, 3])
""")

# Comments are preserved:
mwe("""
1+1 # This comment is preserved
""")
source
MinimalWorkingExamples.mwe_rescueFunction
mwe_rescue([transcript]; kwargs...)

Rescue a copy-pasted Julia REPL transcript into an MWE: strips the julia> prompt, dedents continuation lines, discards printed output, then runs the remaining code through mwe.

If transcript is omitted, it is read from the clipboard.

Keyword arguments

Accepts the same keyword arguments (with the same defaults) as mwe.

Examples

mwe_rescue("""
julia> x = 1 + 1
2

julia> x * 2
4
"""; advertise=false)

Produces the same MWE as mwe("x = 1 + 1\nx * 2"; advertise=false).

Note

Only the plain julia> prompt is recognized.

source
MinimalWorkingExamples.mwe_invertFunction
mwe_invert([text])

Invert a rendered MWE back into plain code: drop every line that starts with #> (the output lines emitted by mwe/@mwe) and return what's left, unexecuted.

If text is omitted, it is read from the clipboard — e.g. paste in the code block copied from a GitHub issue. The inverted code is copied back to the clipboard when possible.

Examples

mwe_invert("""
1 + 1
#> 2
""")

Returns "1 + 1".

source
MinimalWorkingExamples.set_defaults!Function
set_defaults!(; kwargs...)

Persistently override the default keyword arguments of @mwe and mwe using Preferences.jl.

Any of venue, temp, newprocess, manifest, advertise, verbose, versioninfo, julia_args, plot_dir, and preview may be set. Passing nothing for a key clears it, reverting to the built-in default.

Examples

# Always format for Slack and skip the isolated environment:
set_defaults!(venue=:slack, temp=false)

# Go back to the built-in venue default:
set_defaults!(venue=nothing)
source
MinimalWorkingExamples.previewFunction
preview(result::MWEResult; target::Union{Symbol,Nothing}=nothing)

Render the Markdown of an MWEResult to HTML, to check what the MWE will look like before posting it. Plot placeholders are replaced by the actual saved image files.

target picks the viewer: :editor for the host editor's viewer panel, :browser for the default browser, or nothing (the default) to use the editor panel when available and fall back to the browser otherwise.

Returns the path of the generated HTML file.

Examples

result = mwe()
preview(result)
preview(result; target = :browser)
source