Skip to content

Add DesmosLib module for Desmos-specific functions #75

Description

@hyrodium

Add DesmosLib module for Desmos-specific functions

Problem

Currently, users who want to use Desmos-native function names in @desmos macro face challenges because some function names get incorrectly parsed as multi-character variables with subscripts.

Example:

@desmos begin
    nCr(n, k)  # Currently parsed as n_{Cr}(n, k) ✗
end

Users must use Julia-style names instead:

@desmos begin
    binomial(n, k)  # Works, converts to \operatorname{nCr}(n,k) ✓
end

While this works functionally, it's not intuitive for users familiar with Desmos who want to use Desmos function names directly.

Proposed Solution

Add a DesmosLib submodule that provides:

  1. Namespace for Desmos-native function names - allows using Desmos function names directly
  2. Dummy function definitions with documentation for IDE support
  3. Proper LaTeX conversion when used inside @desmos macro

Usage Example

using Desmos
using Desmos: DesmosLib  # Optional, but for IDE completion

@desmos begin
    # Desmos-native names (via DesmosLib)
    DesmosLib.nCr(n, k)  # → \operatorname{nCr}(n,k)
    DesmosLib.nPr(n, r)  # → \operatorname{nPr}(n,r)

    # Julia-style names (still work)
    binomial(n, k)  # → \operatorname{nCr}(n,k)

    # Distributions with Desmos naming
    DesmosLib.normaldist(μ, σ)  # → \operatorname{normaldist}(μ,σ)
    Normal(μ, σ)  # → \operatorname{normaldist}(μ,σ) (also works)
end

Implementation Tasks

  • Create src/DesmosLib.jl module file
  • Add dummy function definitions with docstrings
  • Update _latexify_call to handle DesmosLib.function syntax (qualified names)
  • Add mappings in latexify_symbols.jl for qualified names
  • Write tests in test/latexify.jl
  • Update documentation with examples
  • Export DesmosLib from main module

Functions to Include

High Priority (more intuitive with Desmos names)

  • nCr(n, k) - combinations (currently binomial)
  • nPr(n, r) - permutations (currently no Julia equivalent)
  • normaldist(μ, σ) - normal distribution (currently Normal)
  • uniformdist(a, b) - uniform distribution (currently Uniform)

Medium Priority (for completeness)

  • Other distribution functions: tdist, chisqdist, binomialdist, poissondist, geodist
  • Visualization functions: histogram, dotplot, boxplot

Low Priority (already work well with Julia names)

  • Statistical functions that map 1:1 with Julia Base

Alternatives Considered

Option 1: Allow nCr without qualification

  • Requires complex macro hygiene
  • Hard to maintain
  • No IDE support

Option 2: Current approach with Julia names only

  • Works functionally
  • Less intuitive for Desmos users
  • Good for Julia users

Chosen: Option 3 (DesmosLib module)

  • Clean namespace separation
  • IDE support possible
  • Explicit and maintainable
  • Users can choose: DesmosLib.nCr (Desmos-style) or binomial (Julia-style)
  • Best of both worlds

Notes

  • This is a non-breaking addition
  • Existing code continues to work
  • Users can gradually adopt DesmosLib for better Desmos compatibility
  • Both styles can coexist in the same @desmos block

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions