Skip to content

Commit

Permalink
Add more docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
kwankyu committed Jul 8, 2024
1 parent 7a9fd5e commit 5a94a77
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/sage/misc/latex.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import random
import re
import shutil
import time
from subprocess import call, run, Popen, PIPE
from tempfile import TemporaryDirectory

Expand Down Expand Up @@ -1880,28 +1881,27 @@ def view(objects, title='Sage', debug=False, sep='', tiny=False,
return
output_file = os.path.join(tmp.name, "sage." + suffix)

# this should get changed if we switch the stuff in misc.viewer to
# producing lists
if debug:
print(f'temporary file: "{output_file}"')
print(f'viewer: "{viewer}"')

Check warning on line 1886 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1885-L1886

Added lines #L1885 - L1886 were not covered by tests

# return immediately but only clean up the temporary file after the viewer
# is open
# We return immediately but the temporary file is cleaned up after the viewer
# opens the file, hopefully.

process = Popen([viewer, output_file], stdout=PIPE, stderr=PIPE)

Check warning on line 1891 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1891

Added line #L1891 was not covered by tests

def cleanup_temp_file():
process.wait()
time.sleep(5)
if tmp:
import time
time.sleep(5)
tmp.cleanup()

Check warning on line 1897 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1893-L1897

Added lines #L1893 - L1897 were not covered by tests

from threading import Thread
t = Thread(target=cleanup_temp_file)

Check warning on line 1900 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1900

Added line #L1900 was not covered by tests
t.start()


def pdf(x, filename, tiny=False, engine=None, tightpage=True, margin=None, debug=False):
def pdf(x, filename, tiny=False, tightpage=True, margin=None, engine=None, debug=False):
"""
Create an image from the latex representation of ``x`` and save it as a pdf
file with the given filename.
Expand All @@ -1917,6 +1917,9 @@ def pdf(x, filename, tiny=False, engine=None, tightpage=True, margin=None, debug
- ``tightpage`` -- boolean (default: ``True``); use the LaTeX package
``preview`` with the 'tightpage' option
- ``margin`` -- float (default: no margin); width of border, only effective
with 'tight page'
- ``engine`` -- (default: ``None``) ``'latex'``, ``'pdflatex'``,
``'xelatex'`` or ``'lualatex'``
Expand Down Expand Up @@ -1945,15 +1948,14 @@ def pdf(x, filename, tiny=False, engine=None, tightpage=True, margin=None, debug
'\\PreviewEnvironment{page}%s' % margin_str,
'math_left': '\\begin{page}$',
'math_right': '$\\end{page}'}
title = None
else:
latex_options = {}

Check warning on line 1952 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1952

Added line #L1952 was not covered by tests

# create a string of latex code to write in a file
s = _latex_file_([x], title='', tiny=tiny, debug=debug, **latex_options)
if engine is None:
engine = _Latex_prefs._option["engine"]

Check warning on line 1957 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1955-L1957

Added lines #L1955 - L1957 were not covered by tests
# path name for permanent png output
# path name for permanent pdf output
abs_path_to_pdf = os.path.abspath(filename)

Check warning on line 1959 in src/sage/misc/latex.py

View check run for this annotation

Codecov / codecov/patch

src/sage/misc/latex.py#L1959

Added line #L1959 was not covered by tests
# temporary directory to store stuff
with TemporaryDirectory() as tmp:
Expand Down

0 comments on commit 5a94a77

Please sign in to comment.