|
| 1 | +# `latexify` parameters |
| 2 | + |
| 3 | +This document describes the list of parameters to control the behavior of `latexify`. |
| 4 | + |
| 5 | + |
| 6 | +## `identifiers: dict[str, str]` |
| 7 | + |
| 8 | +Key-value pair of identifiers to replace. |
| 9 | + |
| 10 | +```python |
| 11 | +identifiers = { |
| 12 | + "my_function": "f", |
| 13 | + "my_inner_function": "g", |
| 14 | + "my_argument": "x", |
| 15 | +} |
| 16 | + |
| 17 | +@latexify.function(identifiers=identifiers) |
| 18 | +def my_function(my_argument): |
| 19 | + return my_inner_function(my_argument) |
| 20 | + |
| 21 | +my_function |
| 22 | +``` |
| 23 | + |
| 24 | +$$\mathrm{f}(x) = \mathrm{g}\left(x\right)$$ |
| 25 | + |
| 26 | + |
| 27 | +## `reduce_assignments: bool` |
| 28 | + |
| 29 | +Whether to compose all variables defined before the `return` statement. |
| 30 | + |
| 31 | +The current version of `latexify` recognizes only the assignment statements. |
| 32 | +Analyzing functions with other control flows may raise errors. |
| 33 | + |
| 34 | +```python |
| 35 | +@latexify.function(reduce_assignments=True) |
| 36 | +def f(a, b, c): |
| 37 | + discriminant = b**2 - 4 * a * c |
| 38 | + numerator = -b + math.sqrt(discriminant) |
| 39 | + denominator = 2 * a |
| 40 | + return numerator / denominator |
| 41 | + |
| 42 | +f |
| 43 | +``` |
| 44 | + |
| 45 | +$$\mathrm{f}(a, b, c) = \frac{-b + \sqrt{b^{{2}} - {4} a c}}{{2} a}$$ |
| 46 | + |
| 47 | + |
| 48 | +## `use_math_symbols: bool` |
| 49 | + |
| 50 | +Whether to automatically convert variables with symbol names into LaTeX symbols or not. |
| 51 | + |
| 52 | +```python |
| 53 | +@latexify.function(use_math_symbols=True) |
| 54 | +def greek(alpha, beta, gamma, Omega): |
| 55 | + return alpha * beta + math.gamma(gamma) + Omega |
| 56 | + |
| 57 | +greek |
| 58 | +``` |
| 59 | + |
| 60 | +$$\mathrm{greek}({\alpha}, {\beta}, {\gamma}, {\Omega}) = {\alpha} {\beta} + \Gamma\left({{\gamma}}\right) + {\Omega}$$ |
| 61 | + |
| 62 | + |
| 63 | +## `use_raw_function_name: bool` |
| 64 | + |
| 65 | +Whether to use the original string as the function name or not. |
| 66 | + |
| 67 | +```python |
| 68 | +@latexify.function(use_raw_function_name=True) |
| 69 | +def quadratic_solution(a, b, c): |
| 70 | + return (-b + math.sqrt(b**2 - 4 * a * c)) / (2 * a) |
| 71 | + |
| 72 | +f |
| 73 | +``` |
| 74 | + |
| 75 | +$$\mathrm{quadratic\_solution}(a, b, c) = \frac{-b + \sqrt{b^{{2}} - {4} a c}}{{2} a}$$ |
| 76 | + |
| 77 | +(note that GitHub's LaTeX renderrer does not process underscores correctly.) |
| 78 | + |
| 79 | +## `use_set_symbols: bool` |
| 80 | + |
| 81 | +Whether to use binary operators for set operations or not. |
| 82 | + |
| 83 | +```python |
| 84 | +@latexify.function(use_set_symbols=True) |
| 85 | +def f(x, y): |
| 86 | + return x & y, x | y, x - y, x ^ y, x < y, x <= y, x > y, x >= y |
| 87 | + |
| 88 | +f |
| 89 | +``` |
| 90 | + |
| 91 | +$$\mathrm{f}(x, y) = \left( x \cap y\space,\space x \cup y\space,\space x \setminus y\space,\space x \mathbin{\triangle} y\space,\space {x \subset y}\space,\space {x \subseteq y}\space,\space {x \supset y}\space,\space {x \supseteq y}\right)$$ |
| 92 | + |
| 93 | + |
| 94 | +## `use_signature: bool` |
| 95 | + |
| 96 | +Whether to output the function signature or not. |
| 97 | + |
| 98 | +The default value of this flag depends on the frontend function. |
| 99 | +`True` is used in `latexify.function`, while `False` is used in `latexify.expression`. |
| 100 | + |
| 101 | +```python |
| 102 | +@latexify.function(use_signature=False) |
| 103 | +def f(a, b, c): |
| 104 | + return (-b + math.sqrt(b**2 - 4 * a * c)) / (2 * a) |
| 105 | + |
| 106 | +f |
| 107 | +``` |
| 108 | + |
| 109 | +$$\frac{-b + \sqrt{b^{{2}} - {4} a c}}{{2} a}$$ |
0 commit comments