### Install TeX Live on Ubuntu Source: https://pypi.org/project/latextools/0.5.0 Install a LaTeX distribution on Ubuntu using apt. You can choose from different packages depending on your needs. ```bash sudo apt install texlive # Or texlive-latex-recommended, or texlive-latex-extra ``` -------------------------------- ### Install MacTeX on macOS Source: https://pypi.org/project/latextools/0.5.0 Install the MacTeX LaTeX distribution on macOS using Homebrew. ```bash brew cask install mactex # Or mactex-no-gui ``` -------------------------------- ### Install LatexTools Source: https://pypi.org/project/latextools/0.5.0 Install the LatexTools package using pip. Ensure you are using Python 3. ```bash python3 -m pip install latextools ``` -------------------------------- ### Install Drawsvg and Cairo on Ubuntu Source: https://pypi.org/project/latextools/0.5.0 Install Cairo and the Drawsvg Python package with raster support on Ubuntu. ```bash sudo apt-get install libcairo2 python3 -m pip install "drawsvg[raster]~=2.0" ``` -------------------------------- ### Install Inkscape on macOS Source: https://pypi.org/project/latextools/0.5.0 Install Inkscape on macOS using Homebrew. Inkscape is optional and used for PDF conversions. ```bash brew cask install inkscape ``` -------------------------------- ### Install Drawsvg and Cairo on macOS Source: https://pypi.org/project/latextools/0.5.0 Install Cairo and the Drawsvg Python package with raster support on macOS using Homebrew and pip. ```bash brew install cairo python3 -m pip install "drawsvg[raster]~=2.0" ``` -------------------------------- ### Build and Compile Full LaTeX Project Source: https://pypi.org/project/latextools Demonstrates building a complete LaTeX project, including custom packages and content, and compiling it to a PDF. Requires 'latextools'. ```python import latextools # Build a Latex document packages = [ latextools.pkg.qcircuit, latextools.LatexPackage('geometry', ('paperheight=2.5in','paperwidth=2.5in', 'margin=0.1in','heightrounded')), ] commands = [ latextools.cmd.ceil, ] config = latextools.DocumentConfig('article', ('',)) proj = latextools.LatexProject() content = latextools.BasicContent( r'''%\n\[\n\Qcircuit @R=.1em @C=0.3em @!R {\n&\t \qw \t & \qw & \ctrl{2} & \qw & \qw & \qw & \qw & \qw & \qw \\\n& \qw & \qw & \qw & \qw & \ctrl{1} & \qw & \qw & \qw & \qw \\\n& \push{\ket{0}}\qw & \qw & \targ & \targ & \targ & \targ & \qw & \meter & \qw \\\n& \qw & \qw & \targ & \ctrl{-1} & \qw & \qw & \qw & \qw & \qw \\\n& \qw & \qw & \qw & \targ & \ctrl{-1} & \qw & \qw & \qw & \qw & \qw \\\n& \push{\ket{0}}\qw & \gate{H} & \ctrl{-2} & \ctrl{-1} & \ctrl{1} & \ctrl{2} & \gate{H} & \meter & \qw \\\n& \qw & \qw & \qw & \qw & \qw & \targ & \qw & \qw & \qw & \qw \\\n& \qw & \qw & \qw & \qw & \qw & \qw & \targ & \qw & \qw & \qw \\}% \] ''', packages, commands) doc = content.as_document(path='figs/syndrome-circuit.tex', config=config) doc = latextools.LatexDocument( path='figs/syndrome-circuit.tex', config=config, contents=( latextools.BasicContent('\centering A qcircuit diagram:'), content, )) proj.add_file(doc) # Write Latex source code to current directory (maintains directory structure) proj.write_src('.') # Render Latex proj.add_file(latextools.LatexDocument( path='main.tex', config=config, contents=doc.contents)) pdf = proj.compile_pdf() # With additional command line arguments: #pdf = proj.compile_pdf(options=['-halt-on-error', '-file-line-error', # '-interaction', 'nonstopmode', '-shell-escape']) pdf.save('figs/syndrome-circuit.pdf') pdf # Show preview if this is in a Jupyter notebook ``` -------------------------------- ### Render QCircuit Diagram Source: https://pypi.org/project/latextools/0.5.0 Creates a PDF, PNG, and SVG of a quantum circuit diagram using QCircuit syntax. Ideal for visualizing quantum algorithms. ```python import latextools pdf = latextools.render_qcircuit(r''' % qcircuit code from http://physics.unm.edu/CQuIC/Qcircuit/Qtutorial.pdf & \ctrl{2} & \qw & \gate{H} & \ctrl{1} &\gate{H} & \qw \\ & \qw & \ctrl{1} & \gate{H} & \targ &\gate{H} & \qw \\ & \targ & \targ & \gate{Z} & \qw & \ctrl{-1} &\qw \gategroup{1}{4}{2}{6}{.7em}{--} ''') pdf.save('qcircuit.pdf') pdf.rasterize('qcircuit.png', scale=2) pdf.as_svg().as_drawing(scale=2).save_svg('qcircuit.svg') pdf # Show preview if this is in a Jupyter notebook ``` -------------------------------- ### Build and Render Full LaTeX Project Source: https://pypi.org/project/latextools/0.5.0 Compiles a complete LaTeX project, including custom packages, commands, and content, into a PDF document. This is for complex documents requiring a full LaTeX build process. ```python import latextools # Build a Latex document packages = [ latextools.pkg.qcircuit, latextools.LatexPackage('geometry', ('paperheight=2.5in','paperwidth=2.5in', 'margin=0.1in','heightrounded')), ] commands = [ latextools.cmd.ceil, ] config = latextools.DocumentConfig('article', ('',)) proj = latextools.LatexProject() content = latextools.BasicContent( r'''%\n\[\n\Qcircuit @R=.1em @C=0.3em @!R {\n&\t \qw \t & \qw & \ctrl{2} & \qw & \qw & \qw & \qw & \qw & \qw \\n&\t \qw & \qw & \qw & \qw & \ctrl{1} & \qw & \qw & \qw & \qw \\n&\t \push{\ket{0}}\qw & \qw & \targ & \targ & \targ & \targ & \qw & \meter & \qw \\n&\t \qw & \qw & \targ & \ctrl{-1} & \qw & \qw & \qw & \qw & \qw \\n&\t \qw & \qw & \qw & \targ & \qw & \ctrl{-2} & \qw & \qw & \qw \\n&\t \push{\ket{0}}\qw & \gate{H} & \ctrl{-2} & \ctrl{-1} & \ctrl{1} & \ctrl{2} & \gate{H} & \meter & \qw \\n&\t \qw & \qw & \qw & \qw & \targ & \qw & \qw & \qw & \qw \\n&\t \qw & \qw & \qw & \qw & \qw & \qw & \targ & \qw & \qw & \qw \\n}%\n\] ''', packages, commands) doc = content.as_document(path='figs/syndrome-circuit.tex', config=config) doc = latextools.LatexDocument( path='figs/syndrome-circuit.tex', config=config, contents=( latextools.BasicContent('\centering A qcircuit diagram:'), content, )) proj.add_file(doc) # Write Latex source code to current directory (maintains directory structure) proj.write_src('.') # Render Latex proj.add_file(latextools.LatexDocument( path='main.tex', config=config, contents=doc.contents)) pdf = proj.compile_pdf() # With additional command line arguments: #pdf = proj.compile_pdf(options=['-halt-on-error', '-file-line-error', # '-interaction', 'nonstopmode', '-shell-escape']) pdf.save('figs/syndrome-circuit.pdf') pdf # Show preview if this is in a Jupyter notebook ``` -------------------------------- ### Render LaTeX Table Snippet Source: https://pypi.org/project/latextools/0.5.0 Generates a PDF, PNG, and SVG of a LaTeX table. Useful for displaying tabular data with LaTeX formatting. ```python import latextools import random numbers = [[random.randint(0, 10000) for x in range(4)] for y in range(5)] row = ['&'.join('{}'.format(num) for num in row) for row in numbers] table_body = ' \\ \hline '.join(row) pdf = latextools.render_snippet(r''' \begin{tabular}{c|c|c|c} A & B & C & E \\ \hline\hline ''' + table_body + ''' \\ \end{tabular} '''.strip(), pad=1, ) pdf.save('table.pdf') pdf.rasterize('table.png', scale=2) pdf.as_svg().as_drawing(scale=2).save_svg('table.svg') pdf # Show preview if this is in a Jupyter notebook ``` -------------------------------- ### Render SVG with LaTeX Text Source: https://pypi.org/project/latextools/0.5.0 Creates an SVG drawing containing text with LaTeX equations and macros, then renders the entire drawing as a PDF. Suitable for documents requiring both vector graphics and formatted text. ```python import latextools import drawsvg as draw # pip3 install drawsvg # Create an SVG drawing with latex-formatted text d = draw.Drawing(100, 100, origin='center') d.append(draw.Circle(0, 0, 49, fill='yellow', stroke='black', stroke_width=2)) d.append(draw.Text(r'\Huge$\sqrt{X^\dag}$', 30, 0, 14, center=True)) # Render entire drawing as latex pdf = latextools.render_svg(d) pdf.save('vector2.pdf') pdf.rasterize('vector2.png', scale=2) # Display in Jupyter notebook #pdf.rasterize(scale=2) # Display as PNG pdf # Display as PDF ``` -------------------------------- ### Embed LaTeX in SVG Drawing Source: https://pypi.org/project/latextools/0.5.0 Renders a LaTeX equation as an SVG and embeds it within a larger SVG vector drawing. Useful for creating complex diagrams with mathematical notation. ```python import latextools import drawsvg as draw # pip3 install drawsvg # Render latex latex_eq = latextools.render_snippet( r'$\sqrt{X^\dag}$', commands=[latextools.cmd.all_math]) svg_eq = latex_eq.as_svg() # Use the rendered latex in a vector drawing d = draw.Drawing(100, 100, origin='center') d.append(draw.Circle(0, 0, 49, fill='yellow', stroke='black', stroke_width=2)) d.draw(svg_eq, x=0, y=0, center=True, scale=2.5) d.save_svg('vector.svg') d.save_png('vector.png') # Display in Jupyter notebook #d.rasterize() # Display as PNG d.display_inline() # Display as SVG ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.