Comments (15)
@luisarandas Yes, the poc works on Jupyter and/or Colab and we can add examples.
from latexify_py.
I'd agree with multiple code gen, targeting either Jupyter or algorithmic. I'd be interested in taking a look into algorithmic at some point.
from latexify_py.
I don't like the image approach actually, so going with two codegens is fine.
~~~~
Better to use \hspace{width}
rather than whitespace characters, because indentation does not mean anything about the expression itself. (it also allows us to control the amount of the depth afterwards)
\mathrm{\textbf{foo}}
Better to use \mathbf{foo}
.
See also my previous example.
from latexify_py.
There are several caveats.
Specifically, IPython supports only MathJax, meaning that it accepts only a single expression. To output more complicated LaTeX document, we need to complie the source directly, and convert the generated file to an image that IPython accepts.
In the work above, I used pdflatex and pdf2image. They requires to install external libraries, e.g., texlive with the algorithmicx package (for pdflatex) and Poppler (for pdf2image).
from latexify_py.
An option to implement it for IPython is to use immediate newline in the single expression with appropriate manual spacing, but it requires some hacks. I think it would be better to apply external commands to generate the compiled image.
from latexify_py.
Can this, if implemented, be added to the ipynb
example?
from latexify_py.
I guess composing everything into array
would be another option to show the result on Jupyter. Maybe we can introduce multiple codegen (one for algorithmic, one for jupyter).
from latexify_py.
I have some ideas about this.
- First, we can provide the
ExpressionCodegen
, which convertsast.expr
to LaTeX. I thinkast.expr
is the minimal fragment of AST that we can share the same behavior among different output styles. - Then, we provide several codegens, such as
FunctionCodegen
,AlgorithmCodegen
,IPythonAlgorithmCodegen
, or something else, to process the whole syntax. They invokesExpressionCodegen
internally to obtain the underlying expressions, and organize all results along with the style that the codegen finally produces.
This design has also an advantage about programmatic use of this library. We can define a function latexify.compile_expression("...expr...")
, which directly invokes ExpressionCodegen
and returns the LaTeX. (also discussed in #108)
from latexify_py.
I would think that ExpressionCodegen(ast.NodeVisitor)
would be the parent class to FunctionCodegen
, AlgorithmCodegen
, etc., since I think the visiting of nodes for expressions should be shared among them?
Would you happen to have the LaTeX code for the example MAX_IN_ARRAY
function in the image above? Not super familiar with using Latex in this way, and it would be nice for an example to get a sense of what the end result would be here.
from latexify_py.
ExpressionCodegen(ast.NodeVisitor) would be the parent class to FunctionCodegen, AlgorithmCodegen, etc
We don't need inheritance (and shouldn't adopt inheritance here IMO) because there's basically no advantage over composition in this case. We could define ExpressionCodegen
as just a kind of function.
For the first example, I tried to synthesize the following LaTeX environment:
https://www.overleaf.com/learn/latex/Algorithms
(note that there are many options/variants of this environment)
from latexify_py.
Maybe an required keyword argument to specify the argument to target?
from latexify_py.
I guess you meant some argument to specify the output style. Yes we need to have one for it (and maybe it'd be better to integrate the current function
and expression
behaviors into "style")
from latexify_py.
Maybe adding a sytle=StyleEnum
field in the config, and instead of latexify.expression
being a wrapper around latexify.function
with use_signature=False
. Instead it would be a wrapper with config.style = Style.EXPRESSION
?
That way we could have things like
@latexify.function(style=Style.EXPRESSION)
def fact(n):
return 1 if n == 0 else n * fact(n - 1)
and we could have
Style(str, enum.Enum):
EXPRESSION = "expression"
FUNCTION = "function"
ALGPSEUDOCODE = "algpseudocode"
from latexify_py.
Yes. And we should have functions for every choice of style. As this is an essential config, users shouldn't write the style parameter every time.
from latexify_py.
An option to implement it for IPython is to use immediate newline in the single expression with appropriate manual spacing, but it requires some hacks. I think it would be better to apply external commands to generate the compiled image.
I think it might be nice to try to do this using said hacks so that we don't add unnecessary dependancies.
I don't think it would actually be that difficult. Do you mind if I try to accomplish this, or did you prefer to go the image approach?
from latexify_py.
Related Issues (20)
- Custom multiplication behavior (option to use \cdot everywhere) HOT 1
- 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
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.