R/operators.R

Defines functions under factory

Documented in under

factory <- function(components, base_function){
        force(components)
        force(base_function)
        function(a,b){
	    flag <- list(a,b) |> 
			purrr::map_lgl(
			    .x = _, 
			    .f = \(y) inherits(y, "latex_symb")
			) |> 
			any()
	    result <- if(flag){
		   components(a,b) |> do.call(lsymb, args = _)
	    } else {
		   base_function(a,b)
	    }
	    return(result)
	}
}

`+` <- factory(\(a,b) list(a, "+", b), base::`+`)
`-` <- factory(\(a,b) list(a, "-", b), base::`-`)
`*` <- factory(\(a,b) list(a, b), base::`*`)
`/` <- factory(\(a,b) list("\\frac{", a, "}{", b, "}"), base::`/`)
`^` <- factory(\(a,b) list(a, "^{", b, "}"), base::`^`)

under <- function(a,b) lsymb(a, "_{", b, "}")

Try the latexSymb package in your browser

Any scripts or data that you put into this service are public.

latexSymb documentation built on June 17, 2025, 9:12 a.m.