Comments (7)
Maybe it could be a choice to provide a global function latexify.set_config()
to modify the default behavior:
import latexify
latexify.set_config(...) # Calls it before any @with_latex decorators.
@with_latex
def foobar(...):
...
from latexify_py.
class LatexifyVisitor(ast.NodeVisitor):
# define static variables here like
math_symbol = True
equal_form = r"\triangleq"
# change __init__ into
def __init__(self, **kwargs):
# config part
for k in kwargs.keys():
if k in dir(LatexifyVisitor):
setattr(LatexifyVisitor,k,kwargs[k])
else:
# deal wrong config setting here
...
Will allow all instances of LatexifyVisitor
keep the same config.
from latexify_py.
For this particular implementation, it looks somewhat dangerous because...
- object method (
__init__
) globally changes the class attributes. dir()
returns every visible symbol of all super classes.kwargs
drops much stuff for self-documenting -- using it brings difficulty for further maintenance.
I am thinking of separating configs from the visitor completely rather than directly implementing them into the class.
from latexify_py.
Well...it isn't a strict implementation, I just want to show the logic. Of course there are many ways to strengthen its security, like
class LatexifyVisitor(ast.NodeVisitor):
math_symbol = True
equal_form = r"\triangleq"
config_list=['math_symbol',
'equal_form'
# more could be added here in future
]
and change dir(LatexifyVisitor)
into config_list
, or
simply change
if k in dir(LatexifyVisitor):
into
if not callable(getattr(LatexifyVisitor,k,lambda:1))# or any callable dummy function
will guarantee k is a variable defined in LatexifyVisitor.
I'm just voting for implementing config inside LatexifyVisitor, but if you finally decide to have it outside, I'm also glad to see it. A config working is better than none.
As for documentations, it is true documenting things like kwargs
takes a lot of time and energy. But since latexify is so welcomed and has earned 800+ stars so far, making it more easy to use would make latexify a better tool. All we need to do at present is to add an example at the Jupyter notebook page-I think that is a tutorial good and simple enough for new users.
from latexify_py.
Well, the essential point I am thinking of is these flags should not be class attributes since it would be changed every time we invoked __init__
. And introspection is basically the final choice of implementation which is chosen only when there are no easier solutions.
The first intent of this issue is how to avoid specifying a bunch of flags to @with_latex
for user-default flags. Your solution can resolve it by specifying a particular flag to only the first decoration, but it will also introduce any kind of confusion due to a stateful behavior of the decorator.
it isn't a strict implementation, I just want to show the logic.
I could think so, but couldn't guess which aspect is actually pointed. That's why I said "for this particular implementation..."
not callable(getattr(LatexifyVisitor,k,lambda:1))
will guarantee k is a variable defined in LatexifyVisitor.
Unfortunately no, it still returns many ruins from super classes. Of course we can also take any hacks to avoid them, but this is unneeded burden we have to take here.
from latexify_py.
It seems I have misunderstood your requirements of the config. I'm not experienced in designing configs and thus haven't thought that far.
I would not try to implement the config part in #15 and would return the discussion after another config logic be come up with.
from latexify_py.
This issue is taken by #66 , close for now.
from latexify_py.
Related Issues (20)
- Should `def(x): func(x)` generate `\func x` or `\func \mathopen{}\left( x \mathclose{}\right)`? HOT 2
- Fine-grained control over function name replacements
- Designing "plugin" interface HOT 3
- Use `latex.py` for to standardize codegen HOT 2
- Feedback From a User HOT 14
- Please add support for Python >3.11 HOT 2
- IPython extension to automatically use conversions on displayed objects HOT 1
- Better Identifier For Multi Index and RHS HOT 4
- Can you sub in values for show work? HOT 1
- Сonverting expressions or strings to latex format HOT 5
- Release New Version HOT 6
- Support for sqrt-like nth-roots when rendering x**(1/p)? HOT 2
- Support for log1p and expm1? HOT 4
- `if-elif` statements break if there's no `else` HOT 1
- Typo in \mathopen HOT 3
- Counterintuitive (wrong?) parenthesis when combining exp() and powers HOT 16
- Function docstring and reduce_assignments enabled does not play nice HOT 2
- Include .tex output examples in latexify_py/examples/examples.ipynb HOT 3
- math.pow not working properly on google colab HOT 2
- Non working link on the pypi page of the project HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from latexify_py.