Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include .tex output examples in latexify_py/examples/examples.ipynb #198

Closed
ctarnold opened this issue Dec 5, 2023 · 3 comments
Closed
Assignees
Labels

Comments

@ctarnold
Copy link
Contributor

ctarnold commented Dec 5, 2023

Description

In latexify_py/examples/examples.ipynb, it would be useful to include in one of the examples the option to print to a .tex file.

Ideas of the solution

This feature could involve redefining stdout to a .tex file, or by opening a new .tex file and writing the output of a latexify function to the new .tex file.

Additional context

This feature would allow more ease of use for the client who wishes to paste the tex output to a Latex editor.

@odashi
Copy link
Collaborator

odashi commented Dec 5, 2023

Thanks @ctarnold ! Could you explain more details you are thinking of?

I think the obvious way is to print the wrapped function directly as follows because str() of the wrapped function prints the underlying source.

@latexify.function
def f():
  return 42

with open("some.tex", "w") as fp:
    print(f, file=fp)

The output would contain:

f() = 42

However, this is not beyond the usual practice in Python and I'm wondering whether it is really necessary to note.

@ctarnold
Copy link
Contributor Author

ctarnold commented Dec 5, 2023

Hi @odashi, thank you for your response! I came to this repository as a potential user - I love the product. I initially envisioned the use case of exporting python functions to a research paper drafted in latex. I exist as a subset of users who are much more familiar with latex than they are with python.

I'm considering the example use-case of someone, perhaps in academia, who wants to export a colleague's code to a research draft. That said, your proposed example for exporting to a file would be a better fix. I also tend to agree that for most users familiar with python this example would be trivial. I think this change is minor, but also better communicates this product to others. Let me know your thoughts, and I'm open to modifying my pull-request or resubmitting.

@odashi
Copy link
Collaborator

odashi commented Dec 6, 2023

@ctarnold Thanks for sharing your thought! Okay let's add this snippet into the example.
As the current pull request contains a bit redundant code, I'd be happy if the pull request adopted the above implementation instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants