Skip to content

Commit 255c9f7

Browse files
committed
Add option to change equality sign. Default value is \triangleq
1 parent bfbf0ae commit 255c9f7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/latexify/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717

1818
get_latex = core.get_latex
1919
with_latex = core.with_latex
20+
set_config = core.set_config

src/latexify/core.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
class LatexifyVisitor(node_visitor_base.NodeVisitorBase):
2929
"""Latexify AST visitor."""
3030

31+
# Default config
32+
equality_sign = r"\triangleq"
33+
3134
def __init__(self, math_symbol=False, raw_func_name=False):
3235
self.math_symbol = math_symbol
3336
self.raw_func_name = (
@@ -60,7 +63,7 @@ def visit_FunctionDef(self, node, action): # pylint: disable=invalid-name
6063
name_str = name_str.replace(r"_", r"\_") # fix #31
6164
arg_strs = [self._parse_math_symbols(str(arg.arg)) for arg in node.args.args]
6265
body_str = self.visit(node.body[0])
63-
return name_str + "(" + ", ".join(arg_strs) + r") \triangleq " + body_str
66+
return name_str + "(" + ", ".join(arg_strs) + r") " + self.equality_sign + body_str
6467

6568
def visit_Return(self, node, action): # pylint: disable=invalid-name
6669
del action
@@ -362,3 +365,12 @@ def ret(fn):
362365
return _LatexifiedFunction(fn)
363366

364367
return ret
368+
369+
370+
def set_config(**kwargs):
371+
"""
372+
Parameters :
373+
* `equality_sign`
374+
"""
375+
for key, value in kwargs.items():
376+
setattr(LatexifyVisitor, key, value)

0 commit comments

Comments
 (0)