Reference

Contents

Index

MinimalWorkingExamples.@mweMacro
@mwe begin
    code
end [venue=:gh] [temp=true] [newprocess=true] [manifest=false] [advertise=nothing]
    [packagespecs=PackageSpec[]] [manifest_path=nothing] [verbose=false] [stacktrace=false]

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 output of the final expression (and any print/logging calls) shown as #> comments.

Keyword arguments

  • venue=:gh: output format — :gh for GitHub-Flavored Markdown (default), :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: append a footer noting the date, this package, and Julia version used. Defaults to true for :gh and false for :slack; can be set explicitly to override.
  • 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.
  • stacktrace=false: if true, append the full stacktrace after the error message.
Note

Comments in the code block are not preserved in the output. Use mwe if you need to preserve 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

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")]

Include the stacktrace when an error is thrown:

@mwe begin
    x = [1, 2, 3]
    x[10]
end stacktrace=true
source
MinimalWorkingExamples.mweFunction
mwe([code]; venue=:gh, temp=true, newprocess=true, manifest=false, advertise=nothing,
           packagespecs=PackageSpec[], manifest_path=nothing, verbose=false, stacktrace=false)

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

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.MWEResultType
MWEResult

Wraps the Markdown string produced by @mwe. Displays silently in the REPL (the output is already printed on creation); access the Markdown string via .md.

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, and stacktrace 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