Noah Rahbek Bigum Hansen

Noah Rahbek Bigum Hansen

Mechanical Engineering student at Aarhus University. Interested in vim, software development and guitar pedals.

Configuration

Tungsten is highly configurable, allowing you to tailor the backend, plotting behavior, and keybindings to your workflow. This guide details all available configuration options.

Complete Configuration

The following snippet demonstrates a comprehensive setup using lazy.nvim or a standard init.lua. It highlights common overrides, such as setting the backend path and customizing plotting options.

require("tungsten").setup({
    -- Core Behavior
    backend = "wolfram", -- Default backend
    numeric_mode = false, -- If true, returns decimal approximations by default
    debug = false, -- Enable debug logging
    log_level = "INFO", -- Options: "DEBUG", "INFO", "WARN", "ERROR"
    
    -- Cache Settings
    cache_enabled = true,
    cache_max_entries = 100,
    cache_ttl = 3600, -- Time to live in seconds
    
    -- Execution Settings
    process_timeout_ms = 30000,
    max_jobs = 3, -- Max concurrent async jobs
    
    -- UI & Formatting
    result_separator = " = ",
    result_display = "insert", -- Options: "insert", "float", "virtual"
    persistent_variable_assignment_operator = ":=",
    enable_default_mappings = true,
    
    -- Backend Specific Configuration
    backend_opts = {
        wolfram = {
            wolfram_path = "wolframscript", -- Path to the executable
            -- Custom function name mappings
            function_mappings = {
                sin = "Sin",
                log = "Log",
                -- ... add others as needed
            },
        },
    },

    -- Plotting Configuration
    plotting = {
        backend = "wolfram",
        usetex = true, -- Use LaTeX for label rendering
        latex_engine = "pdflatex",
        outputmode = "latex", -- Options: "latex", "image"
        filename_mode = "sequential",
        viewer_cmd_pdf = "open", -- Command to open PDF plots
        viewer_cmd_png = "open", -- Command to open PNG plots
        snippet_width = "0.8\\linewidth", -- LaTeX width in document
        
        -- Default Ranges
        default_xrange = { -10, 10 },
        default_yrange = { -10, 10 },
        default_zrange = { -10, 10 },
        default_theta_range = { 0, "2*Pi" },
    },
    
    -- Available Domains
    domains = { 
        "arithmetic", 
        "calculus", 
        "linear_algebra", 
        "differential_equations", 
        "plotting", 
        "units" 
    },
    
    -- Event Hooks
    hooks = {},
})

Option Reference

The configuration is broadly divided into general settings, backend options, and plotting configuration.

General Options

OptionTypeDefaultDescription
backendstring"wolfram"The mathematical engine to use. Currently fully supports "wolfram". python support is being built
numeric_modebooleanfalseIf true, results are computed numerically (e.g., 1.414) instead of symbolically (e.g., sqrt(2)).
debugbooleantrueEnables extended debug information.
log_levelstring"INFO"Sets the verbosity of the logger. ("DEBUG", "INFO", "WARN", "ERROR")
process_timeout_msnumber30000Maximum duration (ms) for a backend process before it times out.
max_jobsnumber3Maximum number of concurrent backend jobs allowed.
result_separatorstring" = "The string inserted between the input expression and the result.
result_displaystring"insert"How results are shown. "insert" appends to buffer. "virtual" displays it as virtual text and "float" displays the result in a floating window.
persistent_variable_assignment_operatorstring":="Operator used to define variables that persist across evaluations.
enable_default_mappingsbooleantrueIf true, registers the default <leader>t keybindings.

Backend Options (backend_opts)

This table allows configuration specific to the chosen backend.

Wolfram Configuration (backend_opts.wolfram)

KeyTypeDefaultDescription
wolfram_pathstring"wolframscript"The system executable path for the Wolfram engine.
function_mappingstable{...}Map internal function names (e.g., sin) to backend-specific names (e.g., Sin).

Plotting Configuration (plotting)

Controls how graphs and plots are generated and displayed.

KeyTypeDefaultDescription
usetexbooleantrueIf true, attempts to use LaTeX for rendering math labels in plots.
latex_enginestring"pdflatex"The LaTeX engine executable to use.
outputmodestring"latex"The output format preference. "latex" inserts the LaTeX-string, "viewer" opens the plot in an external viewer and "both" does both.
viewer_cmd_pdfstring"open"System command to view generated PDF files. Used for outputmode="viewer"/"both".
viewer_cmd_pngstring"open"System command to view generated PNG files. Used for outputmode="viewer"/"both".
default_xrangetable{-10, 10}Default domain for the X-axis.
default_yrangetable{-10, 10}Default domain for the Y-axis.
default_theta_rangetable{0, "2*Pi"}Default domain for polar plots.

Keymaps

If enable_default_mappings is set to true, Tungsten registers mappings using which-key.nvim. All mappings are prefixed with <leader>t.

KeyCommandDescription
Evaluate
<leader>teeTungstenEvaluateEvaluate the expression under cursor.
<leader>tedTungstenDefinePersistentVariableDefine a persistent variable.
<leader>teaTungstenShowASTShow the Abstract Syntax Tree for debugging.
<leader>tesTungstenSimplifySimplify the expression.
<leader>tefTungstenFactorFactor the expression.
Solve
<leader>tssTungstenSolveSolve an equation for a variable.
<leader>tsxTungstenSolveSystemSolve a system of equations.
Linear Algebra
<leader>tlgTungstenGaussEliminatePerform Gauss-Jordan elimination.
<leader>tliTungstenLinearIndependentTest for linear independence.
<leader>tlrTungstenRankCalculate the rank of a matrix.
<leader>tle...Sub-menu for Eigenvalues/vectors.
Differential Equations
<leader>tdoTungstenSolveODESolve an Ordinary Differential Equation.
<leader>tdlTungstenLaplaceCompute the Laplace Transform.
<leader>tdiTungstenInverseLaplaceCompute the Inverse Laplace Transform.
Units
<leader>tucTungstenUnitConvertConvert a selected quantity or angle into another unit.
System
<leader>tccTungstenClearCacheClear the internal result cache.
<leader>ttnTungstenToggleNumericModeToggle between symbolic and numeric output.
<leader>tmTungstenPaletteOpen the Command Palette (Telescope).

See Also

  • Installation - Instructions for installing Tungsten and its dependencies.
  • Commands – All commands defined by Tungsten.
  • Domain Pages – Domain-specific guides.