Skip to content

Commit

Permalink
Add paper size option
Browse files Browse the repository at this point in the history
  • Loading branch information
victorbnl committed Oct 10, 2023
1 parent 4d21f11 commit db8e37b
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Added

- Paper size option

## 1.2.0

### Added
Expand Down
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ As a command-line application
.. code-block::
usage: code-to-pdf [-h] [-s STYLE] [--font-size FONT_SIZE] [--linenos LINENOS] [--linenostep LINENOSTEP] [--page-numbers PAGE_NUMBERS]
[--top-margin TOP_MARGIN] [--bottom-margin BOTTOM_MARGIN] [--left-margin LEFT_MARGIN] [--right-margin RIGHT_MARGIN]
[--paper-size PAPER_SIZE] [--top-margin TOP_MARGIN] [--bottom-margin BOTTOM_MARGIN] [--left-margin LEFT_MARGIN]
[--right-margin RIGHT_MARGIN]
source_file out_file
positional arguments:
Expand All @@ -56,6 +57,8 @@ As a command-line application
if `linenos` is enabled, print every n-th line number
--page-numbers PAGE_NUMBERS
whether or not to print page numbers
--paper-size PAPER_SIZE
page format of resulting document
--top-margin TOP_MARGIN
document top margin
--bottom-margin BOTTOM_MARGIN
Expand Down
1 change: 1 addition & 0 deletions code_to_pdf/build/templates/latex.tex.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
\usepackage{fancyvrb}

\usepackage[
paper=<= options.paper_size =>,
top=<= options.top_margin =>,
bottom=<= options.bottom_margin =>,
right=<= options.right_margin =>,
Expand Down
7 changes: 6 additions & 1 deletion code_to_pdf/options/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from pydantic import BaseModel

from code_to_pdf.options.custom_types import FontSize, Margin, PygmentsStyle
from code_to_pdf.options.custom_types import (
FontSize, Margin, PaperSize, PygmentsStyle
)

short_aliases = {"style": "s"}

Expand All @@ -17,6 +19,7 @@ class Options(BaseModel):
linenos: Whether or not to display line numbers.
linenostep: If `linenos` is enabled, print every n-th line number.
page_numbers: Whether or not to print page numbers.
paper_size: Paper size of resulting document.
top_margin: Document top margin.
bottom_margin: Document bottom margin.
left_margin: Document left margin.
Expand All @@ -32,6 +35,8 @@ class Options(BaseModel):

page_numbers: bool = False

paper_size: PaperSize = "a4paper"

top_margin: Margin = "0.4in"
bottom_margin: Margin = "0.4in"
left_margin: Margin = "0.5in"
Expand Down
39 changes: 39 additions & 0 deletions code_to_pdf/options/custom_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,42 @@ def is_pygments_style(value: str) -> str:
PygmentsStyle = Annotated[str, AfterValidator(is_pygments_style)]
FontSize = Literal["10pt", "11pt", "12pt"]
Margin = Annotated[str, StringConstraints(pattern=r"^\d+(\.\d+)?in$")]

PaperSize = Literal[
"a0paper",
"a1paper",
"a2paper",
"a3paper",
"a4paper",
"a5paper",
"a6paper",
"b0paper",
"b1paper",
"b2paper",
"b3paper",
"b4paper",
"b5paper",
"b6paper",
"c0paper",
"c1paper",
"c2paper",
"c3paper",
"c4paper",
"c5paper",
"c6paper",
"b0j",
"b1j",
"b2j",
"b3j",
"b4j",
"b5j",
"b6j",
"ansiapaper",
"ansibpaper",
"ansicpaper",
"ansidpaper",
"ansiepaper",
"letterpaper",
"executivepaper",
"legalpaper",
]

0 comments on commit db8e37b

Please sign in to comment.