Git Product home page Git Product logo

Comments (15)

odashi avatar odashi commented on April 28, 2024 1

@luisarandas Yes, the poc works on Jupyter and/or Colab and we can add examples.

from latexify_py.

ZibingZhang avatar ZibingZhang commented on April 28, 2024 1

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.

odashi avatar odashi commented on April 28, 2024 1

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.

odashi avatar odashi commented on April 28, 2024

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.

odashi avatar odashi commented on April 28, 2024

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.

luisarandas avatar luisarandas commented on April 28, 2024

Can this, if implemented, be added to the ipynb example?

from latexify_py.

odashi avatar odashi commented on April 28, 2024

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).

FgdCA52aMAA5ZQX

from latexify_py.

odashi avatar odashi commented on April 28, 2024

I have some ideas about this.

  • First, we can provide the ExpressionCodegen, which converts ast.expr to LaTeX. I think ast.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 invokes ExpressionCodegen 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.

ZibingZhang avatar ZibingZhang commented on April 28, 2024

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.

odashi avatar odashi commented on April 28, 2024

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.

ZibingZhang avatar ZibingZhang commented on April 28, 2024

Maybe an required keyword argument to specify the argument to target?

from latexify_py.

odashi avatar odashi commented on April 28, 2024

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.

ZibingZhang avatar ZibingZhang commented on April 28, 2024

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.

odashi avatar odashi commented on April 28, 2024

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.

ZibingZhang avatar ZibingZhang commented on April 28, 2024

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.

image

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.