From: Scott Worley Date: Wed, 20 Dec 2023 06:38:46 +0000 (-0800) Subject: Specify page geometry X-Git-Url: http://git.scottworley.com/paperdoorknob/commitdiff_plain/e10b5b6f112c057ab33ad46f8a3385d3bcd23e1d?ds=sidebyside;hp=c04b2e7812ebd48c2d9273122deef888483bc9f6 Specify page geometry --- diff --git a/args.py b/args.py index fb36083..f343a84 100644 --- a/args.py +++ b/args.py @@ -31,6 +31,13 @@ def _command_line_parser() -> ArgumentParser: '--domfilters', help='Which DOM filters to use (default: %(default)s)', default=','.join(f[0] for f in DOMFilters)) + parser.add_argument( + '--geometry', + help='''Page size and margin control +See https://faculty.bard.edu/bloch/geometry.pdf for details +(default: %(default)s)''', + default='paperwidth=5.5in,paperheight=8.5in,nohead,' + + 'tmargin=15mm,hmargin=15mm,bmargin=17mm,foot=4mm') parser.add_argument( '--htmlfilters', help='Which HTML filters to use (default: %(default)s)', @@ -62,4 +69,5 @@ def spec_from_commandline_args() -> Iterator[Spec]: lambda x: ApplyHTMLFilters(args.htmlfilters, x), lambda x: ApplyDOMFilters(args.domfilters, x), PandocTexifier(args.pandoc or 'pandoc'), + args.geometry, texout) diff --git a/paperdoorknob.py b/paperdoorknob.py index 2bcf31a..26eb7be 100644 --- a/paperdoorknob.py +++ b/paperdoorknob.py @@ -37,7 +37,12 @@ def replies(html: BeautifulSoup) -> Iterable[Tag]: def process(spec: Spec) -> None: - spec.texout.write(b'\\documentclass{article}\n\\begin{document}\n') + spec.texout.write(b'\\documentclass{article}\n') + if spec.geometry is not None: + spec.texout.write(b'\\usepackage[' + + spec.geometry.encode('UTF-8') + + b']{geometry}\n') + spec.texout.write(b'\\begin{document}\n') html = parse(spec.htmlfilter(spec.fetcher.fetch(spec.url))) for r in replies(html): spec.domfilter(r) diff --git a/paperdoorknob_test.py b/paperdoorknob_test.py index aa50340..49f1872 100644 --- a/paperdoorknob_test.py +++ b/paperdoorknob_test.py @@ -49,9 +49,11 @@ class BaseTestProcess(ABC): lambda x: x, lambda x: ApplyDOMFilters('NoEdit,NoFooter', x), PandocTexifier('pandoc'), + 'margin=20mm', buf) paperdoorknob.process(spec) assert buf.getvalue() == b'''\\documentclass{article} +\\usepackage[margin=20mm]{geometry} \\begin{document} This is glowfic You \\emph{sure}? @@ -69,6 +71,7 @@ Pretty sure. lambda x: x, lambda x: ApplyDOMFilters('NoEdit,NoFooter', x), texifier, + None, buf) paperdoorknob.process(spec) @@ -80,6 +83,7 @@ Pretty sure. lambda x: x, lambda x: ApplyDOMFilters('NoEdit,NoFooter', x), PandocTexifier('pandoc'), + None, out) paperdoorknob.process(spec) subprocess.run(['pdflatex', 'test.tex'], diff --git a/spec.py b/spec.py index 75d00c3..50746d7 100644 --- a/spec.py +++ b/spec.py @@ -22,4 +22,5 @@ class Spec: htmlfilter: Callable[[bytes], bytes] domfilter: Callable[[Tag], None] texifier: Texifier + geometry: str | None texout: IO[bytes]