]> git.scottworley.com Git - paperdoorknob/commitdiff
Specify page geometry
authorScott Worley <scottworley@scottworley.com>
Wed, 20 Dec 2023 06:38:46 +0000 (22:38 -0800)
committerScott Worley <scottworley@scottworley.com>
Wed, 20 Dec 2023 06:38:46 +0000 (22:38 -0800)
args.py
paperdoorknob.py
paperdoorknob_test.py
spec.py

diff --git a/args.py b/args.py
index fb36083b28b9bcf852d37963f8b53c33760819d3..f343a84a71d2ef0a2394ec71c84d7e1c932cbd3a 100644 (file)
--- 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)
index 2bcf31afe3c1b38407eec51f79babed956847fc9..26eb7be054a823b6183bea6dff3415dfef713a6a 100644 (file)
@@ -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)
index aa50340ecfd7709ed3437b9ce006d22a5fe1804d..49f1872842ea2e61503fd119942c68bfa0eb6bcc 100644 (file)
@@ -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 75d00c36f2040557d498eded29fde11dea2ea4e2..50746d75e172bc58ea48584b4468baaa5ab8b161 100644 (file)
--- 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]