Skip to content

Conversation

zjrwtx
Copy link
Collaborator

@zjrwtx zjrwtx commented May 8, 2025

Description

close #1908

Checklist

Go over all the following points, and put an x in all the boxes that apply.

  • I have read the CONTRIBUTION guide (required)
  • I have linked this PR to an issue using the Development section on the right sidebar or by adding Fixes #issue-number in the PR description (required)
  • I have checked if any dependencies need to be added or updated in pyproject.toml and uv lock
  • I have updated the tests accordingly (required for a bug fix or a new feature)
  • I have updated the documentation if needed:
  • I have added examples if this is a new feature

If you are unsure about any of these, don't hesitate to ask. We are here to help!

@zjrwtx zjrwtx marked this pull request as draft May 8, 2025 12:32
@zjrwtx zjrwtx self-assigned this May 9, 2025
@zjrwtx zjrwtx marked this pull request as ready for review May 9, 2025 11:24
@zjrwtx zjrwtx requested a review from Wendong-Fan May 9, 2025 11:26
@zjrwtx
Copy link
Collaborator Author

zjrwtx commented May 9, 2025

image

@zjrwtx zjrwtx requested a review from MuggleJinx May 9, 2025 14:11
@JINO-ROHIT
Copy link
Collaborator

Thanks! quick question, does this also compile on windows with no errors? used to run into bit of complexities with this library on win

@zjrwtx
Copy link
Collaborator Author

zjrwtx commented May 11, 2025

Thanks! quick question, does this also compile on windows with no errors? used to run into bit of complexities with this library on win

thanks @JINO-ROHIT ,i havent test on windows,cause im using macos right now. and i have already tested it on macos,it needs the users to install the latex compile before using this,i will test on windows also,please letme know your detailed problems when runing this in windows

@JINO-ROHIT
Copy link
Collaborator

of course, ill help test this on my windows machine

@zjrwtx
Copy link
Collaborator Author

zjrwtx commented May 12, 2025

of course, ill help test this on my windows machine

thanks @JINO-ROHIT !

@JINO-ROHIT
Copy link
Collaborator

hii @zjrwtx , just tested a bit, so for windows installating pylatex alone doesnt work, theres quite a bit of complication 'steps' you had to do to get it working on windows, attaching this manual - https://latextools.readthedocs.io/en/latest/install/#windows

  1. we either mention this somewhere as a caveat.
  2. look for some other alt, thats more easily compilable for all ecosystems.

@zjrwtx
Copy link
Collaborator Author

zjrwtx commented May 14, 2025

hii @zjrwtx , just tested a bit, so for windows installating pylatex alone doesnt work, theres quite a bit of complication 'steps' you had to do to get it working on windows, attaching this manual - https://latextools.readthedocs.io/en/latest/install/#windows

  1. we either mention this somewhere as a caveat.
  2. look for some other alt, thats more easily compilable for all ecosystems.

thanks for your help @JINO-ROHIT .in macos ,after installing the pylatex,we also need to install some compile latex enginee ,i guess we could let the user know about this. what do you think? cc @Wendong-Fan @MuggleJinx

@Wendong-Fan
Copy link
Member

hii @zjrwtx , just tested a bit, so for windows installating pylatex alone doesnt work, theres quite a bit of complication 'steps' you had to do to get it working on windows, attaching this manual - https://latextools.readthedocs.io/en/latest/install/#windows

  1. we either mention this somewhere as a caveat.
  2. look for some other alt, thats more easily compilable for all ecosystems.

thanks for your help @JINO-ROHIT .in macos ,after installing the pylatex,we also need to install some compile latex enginee ,i guess we could let the user know about this. what do you think? cc @Wendong-Fan @MuggleJinx

thanks @JINO-ROHIT and @zjrwtx , It would be better if we can make it simpler for the user, would https://github.com/rstudio/tinytex and https://www.gnu.org/software/groff/ be helpful?

@Wendong-Fan Wendong-Fan added the Waiting for Update PR has been reviewed, need to be updated based on review comment label May 18, 2025
@Wendong-Fan Wendong-Fan added this to the Sprint 29 milestone May 18, 2025
@@ -148,40 +148,73 @@ def _write_docx_file(self, file_path: Path, content: str) -> None:
document.save(str(file_path))
logger.debug(f"Wrote DOCX to {file_path} with default formatting")

def _write_pdf_file(self, file_path: Path, content: str, **kwargs) -> None:
def _write_pdf_file(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve, we can add error handling:

Suggested change
def _write_pdf_file(
try:
# PDF generation code
except ImportError as e:
raise RuntimeError(f"Required library not installed: {e}")
except Exception as e:
raise RuntimeError(f"Failed to generate PDF: {e}")

Copy link
Collaborator

@MuggleJinx MuggleJinx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest looks cool to me.

Comment on lines 211 to 213
print(
"Example 7: Please give me a pdf file with formulas of advanced mathematics"
)
Copy link
Member

@lightaime lightaime May 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(
"Example 7: Please give me a pdf file with formulas of advanced mathematics"
)
print(f"Example 7: {latex_pdf_query})


camel_agent.reset()
response = camel_agent.step(pdf_query)
print("Example 7: what is multiagent?please export them as pdf file")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print("Example 7: what is multiagent?please export them as pdf file")
print(f"Example 8: {pdf_query}")



# Example 8: what is multiagent?please export them as pdf file
pdf_query = """what is multiagent?please export them as pdf file"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pdf_query = """what is multiagent?please export them as pdf file"""
pdf_query = """what is multiagent? Please export them as pdf file"""

@@ -148,40 +148,73 @@ def _write_docx_file(self, file_path: Path, content: str) -> None:
document.save(str(file_path))
logger.debug(f"Wrote DOCX to {file_path} with default formatting")

def _write_pdf_file(self, file_path: Path, content: str, **kwargs) -> None:
def _write_pdf_file(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add dependencies_required decorator

Copy link
Member

@lightaime lightaime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @zjrwtx! It would be cool to record a demo on this!

@zjrwtx
Copy link
Collaborator Author

zjrwtx commented May 23, 2025

Thanks @zjrwtx! It would be cool to record a demo on this!

thanks @lightaime ,i will do that.

@zjrwtx
Copy link
Collaborator Author

zjrwtx commented May 23, 2025

The rest looks cool to me.

thanks @MuggleJinx

@zjrwtx zjrwtx removed the Waiting for Update PR has been reviewed, need to be updated based on review comment label May 25, 2025
Copy link
Member

@Wendong-Fan Wendong-Fan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @zjrwtx , left some comments below and added one more PR: #2485, feel free to review and let me know if there's anything need further discussion

"""
from fpdf import FPDF
if use_latex:
from pylatex import ( # type: ignore[import-not-found, import-untyped]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why skip mypy test here, should we add pylatex to pyproject.toml?

Comment on lines 160 to 170
use_latex (bool): Whether to use LaTeX for rendering .
(requires LaTeX toolchain)
If False, uses FPDF for simpler PDF generation.
(default: False)

Raises:
RuntimeError: If the 'fpdf' library is not installed.
RuntimeError: If the 'pylatex' library is not installed
when use_latex=True.
RuntimeError: If the 'fpdf' library is not installed
when use_latex=False.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring format

            use_latex (bool): Whether to use LaTeX for rendering. (requires 
                LaTeX toolchain). If False, uses FPDF for simpler PDF 
                generation. (default: :obj: `False`)

        Raises:
            RuntimeError: If the 'pylatex' or 'fpdf' library is not installed
                when use_latex=True.
        """


# Example 7: Please give me a pdf file with formulas of advanced mathematics
latex_pdf_query = (
"""Please give me a pdf file with formulas of advanced mathematics."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Please give me a pdf file with formulas of advanced mathematics."""
"""Please give me a pdf file with formulas of advanced mathematics."""

pdf.multi_cell(0, line_height, para)
else:
pdf.ln(line_height) # Add empty line
logger.debug(f"Wrote PDF (with LaTeX) to {file_path}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.debug(f"Wrote PDF (with LaTeX) to {file_path}")
logger.debug(f"Wrote PDF (with LaTeX) to {file_path}")

Comment on lines 187 to 188
if '$' in line:
doc.append(Math(data=line.strip('$')))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here seems could be buggy if a line contains $ but is not a simple math expression enclosed by $, like"Price: $10")

@Wendong-Fan Wendong-Fan merged commit cb9fc9f into master May 25, 2025
8 checks passed
@Wendong-Fan Wendong-Fan deleted the filewrite branch May 25, 2025 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[Feature Request] FileWriteToolkit support latex for pdf writing
5 participants