notex-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- notex/__init__.py +52 -0
- notex/cli.py +403 -0
- notex/scaffold.py +87 -0
- notex/sessions.py +177 -0
- notex/templates/LICENSE +674 -0
- notex/templates/cols-formulae/letterfonts.tex +6 -0
- notex/templates/cols-formulae/macros.tex +40 -0
- notex/templates/cols-formulae/preamble.tex +23 -0
- notex/templates/cols-formulae/template.tex +14 -0
- notex/templates/grand/bibliography.bib +0 -0
- notex/templates/grand/chapters/ch1.tex +5 -0
- notex/templates/grand/letterfonts.tex +6 -0
- notex/templates/grand/macros.tex +33 -0
- notex/templates/grand/preamble.tex +161 -0
- notex/templates/grand/template.tex +27 -0
- notex/templates/note/letterfonts.tex +6 -0
- notex/templates/note/macros.tex +33 -0
- notex/templates/note/preamble.tex +163 -0
- notex/templates/note/template.tex +28 -0
- notex/templates/problems/letterfonts.tex +6 -0
- notex/templates/problems/macros.tex +46 -0
- notex/templates/problems/preamble.tex +143 -0
- notex/templates/problems/template.tex +28 -0
- notex/templates/single-formulae/letterfonts.tex +6 -0
- notex/templates/single-formulae/macros.tex +40 -0
- notex/templates/single-formulae/preamble.tex +22 -0
- notex/templates/single-formulae/template.tex +13 -0
- notex/terminal.py +195 -0
- notex_cli-0.1.0.dist-info/METADATA +141 -0
- notex_cli-0.1.0.dist-info/RECORD +34 -0
- notex_cli-0.1.0.dist-info/WHEEL +4 -0
- notex_cli-0.1.0.dist-info/entry_points.txt +5 -0
- notex_cli-0.1.0.dist-info/licenses/LICENSE +674 -0
- notex_cli-0.1.0.dist-info/licenses/notex/templates/LICENSE +674 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
% general imports %
|
|
2
|
+
\usepackage{xifthen}
|
|
3
|
+
\usepackage{tcolorbox}
|
|
4
|
+
\usepackage{theoremref}
|
|
5
|
+
\usepackage{enumitem}
|
|
6
|
+
\usepackage{bookmark}
|
|
7
|
+
\usepackage{comment}
|
|
8
|
+
\usepackage{xcolor}
|
|
9
|
+
\usepackage{transparent}
|
|
10
|
+
\usepackage{varwidth}
|
|
11
|
+
\usepackage{multicol}
|
|
12
|
+
\usepackage{import}
|
|
13
|
+
\usepackage{pdfpages}
|
|
14
|
+
\usepackage{titletoc}
|
|
15
|
+
\usepackage{lmodern}
|
|
16
|
+
|
|
17
|
+
% math imports
|
|
18
|
+
\usepackage{amsmath,amsfonts,amsthm,amssymb,mathtools}
|
|
19
|
+
\usepackage[varbb]{newpxmath}
|
|
20
|
+
\usepackage[makeroom]{cancel}
|
|
21
|
+
\usepackage{xfrac}
|
|
22
|
+
\usepackage{array}
|
|
23
|
+
|
|
24
|
+
% tikz imports
|
|
25
|
+
\usepackage{tikz-cd}
|
|
26
|
+
\usepackage{tikz}
|
|
27
|
+
\usepackage{scalerel}
|
|
28
|
+
\usepackage{pict2e}
|
|
29
|
+
\usepackage{tkz-euclide}
|
|
30
|
+
\usepackage{tikzsymbols}
|
|
31
|
+
\usetikzlibrary{calc}
|
|
32
|
+
\usetikzlibrary{patterns,arrows.meta}
|
|
33
|
+
\usetikzlibrary{shadows}
|
|
34
|
+
\usetikzlibrary{external}
|
|
35
|
+
|
|
36
|
+
% cs imports
|
|
37
|
+
\usepackage[algoruled,linesnumbered,titlenumbered]{algorithm2e}
|
|
38
|
+
|
|
39
|
+
% pgfplots
|
|
40
|
+
\usepackage{pgfplots}
|
|
41
|
+
\pgfplotsset{compat=newest}
|
|
42
|
+
\usepgfplotslibrary{statistics}
|
|
43
|
+
\usepgfplotslibrary{fillbetween}
|
|
44
|
+
|
|
45
|
+
\definecolor{clink}{HTML}{002137}
|
|
46
|
+
\usepackage{hyperref}
|
|
47
|
+
\hypersetup{%
|
|
48
|
+
pdftitle = {Problems},
|
|
49
|
+
colorlinks = true,
|
|
50
|
+
linkcolor = clink,
|
|
51
|
+
bookmarksnumbered = true,
|
|
52
|
+
bookmarksopen = true
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
% language
|
|
56
|
+
\usepackage[polish]{babel}
|
|
57
|
+
\usepackage[utf8]{inputenc}
|
|
58
|
+
\usepackage[T1]{fontenc}
|
|
59
|
+
|
|
60
|
+
% general settings
|
|
61
|
+
\setlength{\parindent}{1cm}%
|
|
62
|
+
\setlist[enumerate,1]{label=\textbf{(\alph*)}}
|
|
63
|
+
|
|
64
|
+
\addto\captionspolish{\renewcommand{\figurename}{Schemat}}
|
|
65
|
+
\addto\captionspolish{\renewcommand{\chaptername}{Lista}}
|
|
66
|
+
\addto\captionspolish{\renewcommand{\contentsname}{Spis zadań.}}
|
|
67
|
+
|
|
68
|
+
% predefined sections
|
|
69
|
+
\tcbuselibrary{theorems, breakable, skins, hooks}
|
|
70
|
+
|
|
71
|
+
% ~~~
|
|
72
|
+
% problem box
|
|
73
|
+
% ~~~
|
|
74
|
+
|
|
75
|
+
% colors
|
|
76
|
+
\definecolor{problembg}{HTML}{f8f9fa}
|
|
77
|
+
\definecolor{problemframe}{HTML}{e9ecef}
|
|
78
|
+
\definecolor{problemdef}{HTML}{212529}
|
|
79
|
+
|
|
80
|
+
\newtcbtheorem[number within=section]{Problem}{Zadanie}
|
|
81
|
+
{%
|
|
82
|
+
enhanced,
|
|
83
|
+
breakable,
|
|
84
|
+
oversize,
|
|
85
|
+
colback = problembg,
|
|
86
|
+
colframe = problemframe,
|
|
87
|
+
coltitle = problemdef,
|
|
88
|
+
sharp corners,
|
|
89
|
+
detach title,
|
|
90
|
+
before upper=\tcbtitle\quad,
|
|
91
|
+
fonttitle = \bfseries\sffamily,
|
|
92
|
+
description font = \mdseries,
|
|
93
|
+
separator sign none,
|
|
94
|
+
}
|
|
95
|
+
{problem}
|
|
96
|
+
|
|
97
|
+
% command
|
|
98
|
+
\newcommand{\problem}[2]
|
|
99
|
+
{%
|
|
100
|
+
\begin{Problem}{#1}{}
|
|
101
|
+
#2
|
|
102
|
+
\end{Problem}
|
|
103
|
+
}%
|
|
104
|
+
|
|
105
|
+
% ~~~
|
|
106
|
+
% formula box
|
|
107
|
+
% ~~~
|
|
108
|
+
|
|
109
|
+
% colors
|
|
110
|
+
\definecolor{formulabg}{HTML}{f6f2f0}
|
|
111
|
+
\definecolor{formulaframe}{HTML}{d0b49f}
|
|
112
|
+
\definecolor{formuladef}{HTML}{212529}
|
|
113
|
+
|
|
114
|
+
\newtcbtheorem[number within=section]{Formula}{}
|
|
115
|
+
{%
|
|
116
|
+
enhanced,
|
|
117
|
+
breakable,
|
|
118
|
+
colback = formulabg,
|
|
119
|
+
coltitle = formuladef,
|
|
120
|
+
frame hidden,
|
|
121
|
+
boxrule = 0sp,
|
|
122
|
+
borderline west = {2pt}{0pt}{formulaframe},
|
|
123
|
+
sharp corners,
|
|
124
|
+
detach title,
|
|
125
|
+
before upper = \tcbtitle\par\smallskip,
|
|
126
|
+
fonttitle = \bfseries\sffamily,
|
|
127
|
+
description font = \mdseries,
|
|
128
|
+
separator sign none,
|
|
129
|
+
segmentation style={solid, formulaframe},
|
|
130
|
+
}
|
|
131
|
+
{formula}
|
|
132
|
+
|
|
133
|
+
\newcommand{\formula}[2]
|
|
134
|
+
{%
|
|
135
|
+
\begin{Formula}{#1}{}
|
|
136
|
+
#2
|
|
137
|
+
\end{Formula}
|
|
138
|
+
}%
|
|
139
|
+
|
|
140
|
+
% contents
|
|
141
|
+
\titlecontents{part}[0pt]{\normalsize\bfseries\protect\addvspace{15pt}}%
|
|
142
|
+
{}{\partname{} }%
|
|
143
|
+
{\enspace\titlerule\contentspage}%
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
\documentclass{report}
|
|
2
|
+
|
|
3
|
+
\input{preamble}
|
|
4
|
+
\input{macros}
|
|
5
|
+
\input{letterfonts}
|
|
6
|
+
|
|
7
|
+
\title{\Huge{<nTeX>[title]}}
|
|
8
|
+
\author{\huge{<nTeX>[name]}}
|
|
9
|
+
\date{\today}
|
|
10
|
+
|
|
11
|
+
\begin{document}
|
|
12
|
+
|
|
13
|
+
\maketitle
|
|
14
|
+
\pdfbookmark[section]{\contentsname}{toc}
|
|
15
|
+
\tableofcontents
|
|
16
|
+
\pagebreak
|
|
17
|
+
|
|
18
|
+
\setcounter{chapter}{8}
|
|
19
|
+
\chapter{Formularz f29}
|
|
20
|
+
\label{cha:list-f29}
|
|
21
|
+
\section{Zadanie 1}
|
|
22
|
+
\problem{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.}
|
|
23
|
+
|
|
24
|
+
\solution Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
|
|
25
|
+
|
|
26
|
+
\answer{Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.}
|
|
27
|
+
|
|
28
|
+
\end{document}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
% sets
|
|
2
|
+
\newcommand{\R}[1][]{\ensuremath{\ifstrempty{#1}{\mathbb{R}}{\mathbb{R}^{#1}}}}
|
|
3
|
+
\newcommand{\N}[1][]{\ensuremath{\ifstrempty{#1}{\mathbb{N}}{\mathbb{N}^{#1}}}}
|
|
4
|
+
\newcommand{\Z}[1][]{\ensuremath{\ifstrempty{#1}{\mathbb{Z}}{\mathbb{Z}^{#1}}}}
|
|
5
|
+
\newcommand{\Q}[1][]{\ensuremath{\ifstrempty{#1}{\mathbb{Q}}{\mathbb{Q}^{#1}}}}
|
|
6
|
+
\newcommand{\C}[1][]{\ensuremath{\ifstrempty{#1}{\mathbb{C}}{\mathbb{C}^{#1}}}}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
\newcommand{\eq}[2]
|
|
2
|
+
{%
|
|
3
|
+
\begin{equation} \label{eq:#1}
|
|
4
|
+
#2
|
|
5
|
+
\end{equation}
|
|
6
|
+
}%
|
|
7
|
+
|
|
8
|
+
\newcommand{\ceq}[1]
|
|
9
|
+
{%
|
|
10
|
+
\begin{equation}
|
|
11
|
+
#1 \nonumber
|
|
12
|
+
\end{equation}
|
|
13
|
+
}%
|
|
14
|
+
|
|
15
|
+
\newcommand{\solution}
|
|
16
|
+
{%
|
|
17
|
+
\setlength{\parindent}{0cm}
|
|
18
|
+
\textbf{\textit{Rozwiązanie.}}
|
|
19
|
+
\newline
|
|
20
|
+
\newline
|
|
21
|
+
\setlength{\parindent}{1cm}
|
|
22
|
+
}%
|
|
23
|
+
|
|
24
|
+
\newcommand{\answer}[1]
|
|
25
|
+
{%
|
|
26
|
+
\begin{flushleft}
|
|
27
|
+
\setlength{\parindent}{0cm}
|
|
28
|
+
\textbf{\textit{Odpowiedź.}}
|
|
29
|
+
\setlength{\parindent}{1cm}
|
|
30
|
+
#1
|
|
31
|
+
\end{flushleft}
|
|
32
|
+
\Qed
|
|
33
|
+
}%
|
|
34
|
+
|
|
35
|
+
\newcommand{\Qed}
|
|
36
|
+
{%
|
|
37
|
+
\begin{flushright}
|
|
38
|
+
\qed
|
|
39
|
+
\end{flushright}
|
|
40
|
+
}%
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
% general imports %
|
|
2
|
+
\usepackage[a4paper, margin=1cm]{geometry}
|
|
3
|
+
\usepackage{multicol}
|
|
4
|
+
\usepackage{color}
|
|
5
|
+
\usepackage{lmodern}
|
|
6
|
+
\usepackage{enumitem}
|
|
7
|
+
|
|
8
|
+
% math imports
|
|
9
|
+
\usepackage{amsmath,amsfonts,amsthm,amssymb,mathtools}
|
|
10
|
+
\usepackage[varbb]{newpxmath}
|
|
11
|
+
\usepackage[makeroom]{cancel}
|
|
12
|
+
\usepackage{xfrac}
|
|
13
|
+
\usepackage{array}
|
|
14
|
+
|
|
15
|
+
% language
|
|
16
|
+
\usepackage[polish]{babel}
|
|
17
|
+
\usepackage[utf8]{inputenc}
|
|
18
|
+
\usepackage[T1]{fontenc}
|
|
19
|
+
|
|
20
|
+
% general settings
|
|
21
|
+
\setlength{\parindent}{1cm}%
|
|
22
|
+
\setlist[enumerate,1]{label=\textbf{(\alph*)}}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
\documentclass{article}
|
|
2
|
+
|
|
3
|
+
\input{preamble}
|
|
4
|
+
\input{macros}
|
|
5
|
+
\input{letterfonts}
|
|
6
|
+
|
|
7
|
+
\begin{document}
|
|
8
|
+
|
|
9
|
+
\thispagestyle{empty}
|
|
10
|
+
\ceq{f^{-1}(y) = x \Longleftrightarrow (f(x) = y)}
|
|
11
|
+
\ceq{\forall_{x \in X} (g \circ f)(x) = g(f(x))}
|
|
12
|
+
|
|
13
|
+
\end{document}
|
notex/terminal.py
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"""Everything that talks to the terminal: colours, status lines, tables and the picker.
|
|
2
|
+
|
|
3
|
+
Status lines and prompts go to stderr, so stdout carries only paths and listings for a shell
|
|
4
|
+
wrapper to capture. The picker uses fzf when installed, the numbered prompt otherwise.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import os
|
|
8
|
+
import shutil
|
|
9
|
+
import subprocess
|
|
10
|
+
import sys
|
|
11
|
+
from collections.abc import Sequence
|
|
12
|
+
from typing import NamedTuple, NoReturn, TextIO
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
'BOLD',
|
|
16
|
+
'BOLD_CYAN',
|
|
17
|
+
'CYAN',
|
|
18
|
+
'DIM',
|
|
19
|
+
'EXIT_CANCELLED',
|
|
20
|
+
'EXIT_ERROR',
|
|
21
|
+
'GREEN',
|
|
22
|
+
'RED',
|
|
23
|
+
'YELLOW',
|
|
24
|
+
'Cell',
|
|
25
|
+
'die',
|
|
26
|
+
'emphasise',
|
|
27
|
+
'info',
|
|
28
|
+
'ok',
|
|
29
|
+
'paint',
|
|
30
|
+
'pick',
|
|
31
|
+
'print_heading',
|
|
32
|
+
'print_path',
|
|
33
|
+
'print_table',
|
|
34
|
+
'warn',
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
# ANSI colour codes, the number in ESC[<number>m. Joined with a semicolon they combine.
|
|
38
|
+
BOLD = '1'
|
|
39
|
+
DIM = '2'
|
|
40
|
+
RED = '31'
|
|
41
|
+
GREEN = '32'
|
|
42
|
+
YELLOW = '33'
|
|
43
|
+
CYAN = '36'
|
|
44
|
+
BOLD_CYAN = f'{BOLD};{CYAN}'
|
|
45
|
+
_ANSI_RESET = '\x1b[0m'
|
|
46
|
+
|
|
47
|
+
# Exit status when the user cancels a prompt: 128 + SIGINT, the same as fzf itself uses.
|
|
48
|
+
EXIT_CANCELLED = 130
|
|
49
|
+
EXIT_ERROR = 1
|
|
50
|
+
|
|
51
|
+
_TABLE_COLUMN_GAP = ' '
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
class Cell(NamedTuple):
|
|
55
|
+
"""One table cell: its text and the colour it is painted in ('' for no colour)."""
|
|
56
|
+
|
|
57
|
+
text: str
|
|
58
|
+
colour: str = ''
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def paint(stream: TextIO, colour: str, text: str) -> str:
|
|
62
|
+
"""Return `text` in an ANSI colour, but only if `stream` is a terminal that shows it.
|
|
63
|
+
|
|
64
|
+
NO_COLOR (when not empty) and TERM=dumb switch colours off, and empty text has nothing
|
|
65
|
+
to colour.
|
|
66
|
+
"""
|
|
67
|
+
if not text:
|
|
68
|
+
return text
|
|
69
|
+
if not stream.isatty() or os.environ.get('NO_COLOR') or os.environ.get('TERM') == 'dumb':
|
|
70
|
+
return text
|
|
71
|
+
return f'\x1b[{colour}m{text}{_ANSI_RESET}'
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def emphasise(text: str) -> str:
|
|
75
|
+
"""Return `text` in bold for use inside a status line."""
|
|
76
|
+
return paint(sys.stderr, BOLD, text)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def info(message: str) -> None:
|
|
80
|
+
"""Print an informational status line to stderr."""
|
|
81
|
+
_print_status('[ INFO ]', CYAN, message)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def ok(message: str) -> None:
|
|
85
|
+
"""Print a success status line to stderr."""
|
|
86
|
+
_print_status('[ OK ]', GREEN, message)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def warn(message: str) -> None:
|
|
90
|
+
"""Print a warning status line to stderr."""
|
|
91
|
+
_print_status('[ WARN ]', YELLOW, message)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def die(message: str) -> NoReturn:
|
|
95
|
+
"""Print an error to stderr and exit with status 1."""
|
|
96
|
+
print(paint(sys.stderr, RED, 'Error:'), message, file=sys.stderr)
|
|
97
|
+
sys.exit(EXIT_ERROR)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def print_heading(text: str) -> None:
|
|
101
|
+
"""Print a heading line to stdout."""
|
|
102
|
+
print(paint(sys.stdout, BOLD_CYAN, text))
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def print_path(relative_path: str) -> None:
|
|
106
|
+
"""Print a path to stdout with its folder part dimmed, so the last name stands out."""
|
|
107
|
+
folder, _, name = relative_path.rpartition('/')
|
|
108
|
+
prefix = f'{folder}/' if folder else ''
|
|
109
|
+
print(paint(sys.stdout, DIM, prefix) + name)
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def print_table(rows: Sequence[Sequence[Cell]], *, right_aligned_column: int) -> None:
|
|
113
|
+
"""Print rows of cells to stdout as aligned columns; the first row is the header.
|
|
114
|
+
|
|
115
|
+
Text is padded to the column width before it is painted, because the invisible colour
|
|
116
|
+
codes would otherwise count towards the width. The last column is not padded.
|
|
117
|
+
"""
|
|
118
|
+
column_count = len(rows[0])
|
|
119
|
+
widths = [max(len(row[index].text) for row in rows) for index in range(column_count)]
|
|
120
|
+
|
|
121
|
+
for row in rows:
|
|
122
|
+
rendered = []
|
|
123
|
+
for index, cell in enumerate(row):
|
|
124
|
+
if index == right_aligned_column:
|
|
125
|
+
text = cell.text.rjust(widths[index])
|
|
126
|
+
elif index == column_count - 1:
|
|
127
|
+
text = cell.text
|
|
128
|
+
else:
|
|
129
|
+
text = cell.text.ljust(widths[index])
|
|
130
|
+
rendered.append(paint(sys.stdout, cell.colour, text) if cell.colour else text)
|
|
131
|
+
|
|
132
|
+
print(_TABLE_COLUMN_GAP.join(rendered))
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def pick(prompt: str, options: Sequence[str], query: str = '') -> str:
|
|
136
|
+
"""Let the user choose one of `options`, or type a name that is not among them.
|
|
137
|
+
|
|
138
|
+
`query` pre-filters the choices. A cancelled prompt exits with EXIT_CANCELLED.
|
|
139
|
+
"""
|
|
140
|
+
if shutil.which('fzf'):
|
|
141
|
+
return _pick_with_fzf(prompt, options, query)
|
|
142
|
+
return _pick_by_number(prompt, options, query)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _print_status(tag: str, colour: str, message: str) -> None:
|
|
146
|
+
"""Print a coloured tag followed by a message to stderr."""
|
|
147
|
+
print(paint(sys.stderr, colour, tag), message, file=sys.stderr)
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _pick_with_fzf(prompt: str, options: Sequence[str], query: str) -> str:
|
|
151
|
+
"""Run fzf over the options and return what the user chose or typed."""
|
|
152
|
+
command = ['fzf', '--prompt', prompt, '--print-query', '-q', query]
|
|
153
|
+
if query:
|
|
154
|
+
# a single match is taken without asking
|
|
155
|
+
command.append('--select-1')
|
|
156
|
+
|
|
157
|
+
result = subprocess.run(
|
|
158
|
+
command, input='\n'.join(options), stdout=subprocess.PIPE, text=True, check=False
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# With --print-query fzf prints the typed query on the first line and the selected
|
|
162
|
+
# option on the second. With nothing selected only the query line is there, and that
|
|
163
|
+
# is how a brand-new name gets through.
|
|
164
|
+
lines = result.stdout.split('\n')
|
|
165
|
+
chosen = lines[1] if len(lines) > 1 and lines[1] else lines[0]
|
|
166
|
+
if result.returncode == EXIT_CANCELLED or not chosen:
|
|
167
|
+
sys.exit(EXIT_CANCELLED)
|
|
168
|
+
return chosen
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _pick_by_number(prompt: str, options: Sequence[str], query: str) -> str:
|
|
172
|
+
"""List the options numbered on stderr and read the answer from stdin.
|
|
173
|
+
|
|
174
|
+
The answer is an option number or a name typed out in full.
|
|
175
|
+
"""
|
|
176
|
+
shown = list(options)
|
|
177
|
+
if query:
|
|
178
|
+
shown = [option for option in shown if query.lower() in option.lower()]
|
|
179
|
+
|
|
180
|
+
for number, option in enumerate(shown, start=1):
|
|
181
|
+
numbered = paint(sys.stderr, DIM, f'{number:3}')
|
|
182
|
+
print(numbered, option, file=sys.stderr)
|
|
183
|
+
|
|
184
|
+
print(paint(sys.stderr, BOLD, prompt), end='', file=sys.stderr, flush=True)
|
|
185
|
+
answer = sys.stdin.readline().strip()
|
|
186
|
+
if not answer:
|
|
187
|
+
sys.exit(EXIT_CANCELLED)
|
|
188
|
+
|
|
189
|
+
# isdecimal, not isdigit: a superscript such as ² is a digit that int() cannot read
|
|
190
|
+
if answer.isdecimal():
|
|
191
|
+
number = int(answer)
|
|
192
|
+
if 0 < number <= len(shown):
|
|
193
|
+
return shown[number - 1]
|
|
194
|
+
|
|
195
|
+
return answer
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: notex-cli
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Dated note folders for university terms, optionally started from LaTeX templates.
|
|
5
|
+
Keywords: latex,notes,university,cli,templates
|
|
6
|
+
Author-Email: Piotr Krzysztof <piotr@codextechnologies.org>
|
|
7
|
+
License-Expression: GPL-3.0-only
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: notex/templates/LICENSE
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Education
|
|
13
|
+
Classifier: Topic :: Text Processing :: Markup :: LaTeX
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
21
|
+
Classifier: Operating System :: MacOS
|
|
22
|
+
Project-URL: Homepage, https://github.com/straightchlorine/noTeX
|
|
23
|
+
Project-URL: Source, https://github.com/straightchlorine/noTeX
|
|
24
|
+
Project-URL: Issues, https://github.com/straightchlorine/noTeX/issues
|
|
25
|
+
Requires-Python: >=3.11
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
<h1 align="center">noTeX</h1>
|
|
29
|
+
|
|
30
|
+
<div align="center">
|
|
31
|
+
|
|
32
|
+
[PyPI](https://pypi.org/project/notex-cli/) · [GitHub](https://github.com/straightchlorine/noTeX)
|
|
33
|
+
|
|
34
|
+
Dated note folders for university terms, optionally started from LaTeX templates.
|
|
35
|
+
|
|
36
|
+
</div>
|
|
37
|
+
|
|
38
|
+
<br>
|
|
39
|
+
|
|
40
|
+
`notex` keeps a notes tree with one dated folder per session, creates the next one for a
|
|
41
|
+
subject (empty or from a LaTeX template) and finds the older ones again. `notex new` prints
|
|
42
|
+
just the path, so a shell function can `cd` straight into the answer.
|
|
43
|
+
|
|
44
|
+
Standard library only, Python 3.11 or newer. fzf is optional; without it you get a plain
|
|
45
|
+
numbered prompt.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- Creates the next session folder for a subject, numbered `NN-%a-%d-%b-%Y`, from an empty
|
|
50
|
+
directory or a LaTeX template
|
|
51
|
+
- Never reuses a number a deleted session left behind, and recognises the older shapes
|
|
52
|
+
(`21-Mar-Sat-2026`, `1-Thu-09-Mar-2023-note`, `01-25-Oct-Sun-2026`) of a hand-made tree
|
|
53
|
+
- Finds the current term by itself: the `*_term` folder holding the newest session
|
|
54
|
+
- Copies a template, renames `template.tex` to `<name>.tex` and fills `<nTeX>[title]`,
|
|
55
|
+
`<nTeX>[name]` and `<nTeX>[afilliation]`, escaping LaTeX
|
|
56
|
+
- Bundles the [latex-template](https://github.com/straightchlorine/latex-template)
|
|
57
|
+
submodule; `NOTEX_TEMPLATES` points at your own tree instead
|
|
58
|
+
- Picks subject, template and kind with fzf, or with a numbered prompt when fzf is missing
|
|
59
|
+
- Lists a term as a table (`notex ls`) and a subject's sessions as paths
|
|
60
|
+
- Prints paths and listings on stdout, status on stderr, colours only on a terminal
|
|
61
|
+
|
|
62
|
+
## Getting started
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
uv tool install notex-cli # or: pipx install notex-cli
|
|
66
|
+
|
|
67
|
+
notex new nlp -t note # today's session for nlp, from the note template
|
|
68
|
+
notex ls # the term, then subject / sessions / last session
|
|
69
|
+
notex go nlp # pick a session and print its path
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Sessions live under ROOT, `~/uni` unless `$NOTEX_ROOT` says otherwise:
|
|
73
|
+
|
|
74
|
+
```
|
|
75
|
+
ROOT/<degree>/<N>_term/<subject>/[<kind>/]<session>
|
|
76
|
+
~/uni/masters/2_term/nlp/03-Sun-15-Nov-2026
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
To land in the folder instead of printing it, a zsh function:
|
|
80
|
+
|
|
81
|
+
```zsh
|
|
82
|
+
uni() { local d; d=$(notex "$@") || return; [[ -d $d ]] && cd "$d" || print -r -- "$d" }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Commands
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
notex new nlp -t note # subject used or created exactly as typed, no prompts
|
|
89
|
+
notex new -T masters/3_term algebra # in another term; created if missing
|
|
90
|
+
notex new # fzf: subject, template, and kind if the subject has one
|
|
91
|
+
notex ls # term, then a table: subject / sessions / last session
|
|
92
|
+
notex ls -T masters/1_term nlp # sessions of subjects whose name contains "nlp"
|
|
93
|
+
notex go # pick any session or subject dir; prints its path
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`-T/--term NAME` (relative to ROOT) works for `new` and `ls`. `new` also takes
|
|
97
|
+
`-t/--template` (`-t none` for an empty folder) and `-k/--kind` (`-k .` for the subject
|
|
98
|
+
itself); names are single folder names, no `..`, no separators. With a subject argument
|
|
99
|
+
nothing is asked, without one the picker fills in subject, template and kind.
|
|
100
|
+
|
|
101
|
+
## Configuration
|
|
102
|
+
|
|
103
|
+
- `NOTEX_ROOT`: the notes root, `~/uni` by default
|
|
104
|
+
- `NOTEX_TEMPLATES`: one subdirectory per template; the bundled ones by default
|
|
105
|
+
- `NOTEX_AUTHOR`: the author line, `git config user.name` then `$USER` by default
|
|
106
|
+
- `NOTEX_AFFILIATION`: the affiliation line, empty by default
|
|
107
|
+
|
|
108
|
+
Colours are off with `NO_COLOR` or `TERM=dumb`.
|
|
109
|
+
|
|
110
|
+
## Programmatic API
|
|
111
|
+
|
|
112
|
+
`import notex` is the library half: `notex.sessions` names and scans, `notex.scaffold`
|
|
113
|
+
creates, and `__all__` lists what is public. `notex.cli` and `notex.terminal` are the
|
|
114
|
+
application: they ask, print and may exit.
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
import datetime
|
|
118
|
+
from pathlib import Path
|
|
119
|
+
|
|
120
|
+
import notex
|
|
121
|
+
|
|
122
|
+
term = notex.newest_term(Path('~/uni').expanduser())
|
|
123
|
+
name = notex.next_session_name(term / 'nlp', None, datetime.date.today())
|
|
124
|
+
notex.create_session(term / 'nlp' / name, None, {})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
`uv sync`, then `just check` (format, lint, types, YAML, tests) and `just fmt` (needs
|
|
130
|
+
`yamlfmt` on `PATH`). A `vX.Y.Z` tag matching `version` in `pyproject.toml` makes Woodpecker
|
|
131
|
+
publish the wheel and sdist to PyPI, so the repository needs a `pypi_token` secret. Push the
|
|
132
|
+
same tag to the GitHub mirror and `.github/workflows/release.yml` waits for the files on
|
|
133
|
+
PyPI, downloads them, checks their sha256 and creates the GitHub release.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
<div align="center">
|
|
138
|
+
|
|
139
|
+
To the only God, be honour and glory for ever and ever.
|
|
140
|
+
|
|
141
|
+
</div>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
notex/__init__.py,sha256=OxOWaK4Q2nTj8uhI-6Wxu-Lvu85R_RE5kvVQ4d9tyEo,1342
|
|
2
|
+
notex/cli.py,sha256=2DUdDarO2-W4ch5aEQhwizZNIru7CIxNs8LPAgq8Mvk,15029
|
|
3
|
+
notex/scaffold.py,sha256=K02s9CbRAZNfNkPtUFhsefBDI4EQZhVgK9UgTKARgLk,3419
|
|
4
|
+
notex/sessions.py,sha256=g1JZLwBBuVjfQTXF8M6XtRpIAUB4TE6KhoaM_km1OGU,6546
|
|
5
|
+
notex/templates/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
6
|
+
notex/templates/cols-formulae/letterfonts.tex,sha256=YdNOLBIdK9OVFI7LlPrhefb_g7Qu6FVnXncNpFOjbbg,407
|
|
7
|
+
notex/templates/cols-formulae/macros.tex,sha256=tbU3Oq3mYAX9bRgyWOeXHcUvtUy6D8-R4tBLpg1VAmM,565
|
|
8
|
+
notex/templates/cols-formulae/preamble.tex,sha256=J7EX4Hf-QNEQRRo45v9ZwSzTxeLGXLa0DbJJI64om40,525
|
|
9
|
+
notex/templates/cols-formulae/template.tex,sha256=0prj5BvKK04NhUj9-2Ozd2g_EU05IEhp1igQdfD4Hz0,258
|
|
10
|
+
notex/templates/grand/bibliography.bib,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
+
notex/templates/grand/chapters/ch1.tex,sha256=v7tP_a4LlZxWtwRHe6kfpMCVcFeZtxAlSCgxEdMGXaM,73
|
|
12
|
+
notex/templates/grand/letterfonts.tex,sha256=YdNOLBIdK9OVFI7LlPrhefb_g7Qu6FVnXncNpFOjbbg,407
|
|
13
|
+
notex/templates/grand/macros.tex,sha256=02famfsp3A4ZSMX15OURGp5-GPgJ2BeEsHGS5_5XKDE,484
|
|
14
|
+
notex/templates/grand/preamble.tex,sha256=XMWS2HVq_vUYqeutY36s8klhlo1euZoMX61kdz36rbc,3613
|
|
15
|
+
notex/templates/grand/template.tex,sha256=__Cusayu_mFx4LxPR1Eo5vYa5zICzHnfg_tJURPJV8I,428
|
|
16
|
+
notex/templates/note/letterfonts.tex,sha256=YdNOLBIdK9OVFI7LlPrhefb_g7Qu6FVnXncNpFOjbbg,407
|
|
17
|
+
notex/templates/note/macros.tex,sha256=02famfsp3A4ZSMX15OURGp5-GPgJ2BeEsHGS5_5XKDE,484
|
|
18
|
+
notex/templates/note/preamble.tex,sha256=JqQCQrTBUPd_WG--oQaJ-AqJjeSEEicqyIu72rZuFpM,3460
|
|
19
|
+
notex/templates/note/template.tex,sha256=qkqChxwiu1rjBfLeGZsxUt53x8uhpX7a3wP23FgbBBg,1218
|
|
20
|
+
notex/templates/problems/letterfonts.tex,sha256=YdNOLBIdK9OVFI7LlPrhefb_g7Qu6FVnXncNpFOjbbg,407
|
|
21
|
+
notex/templates/problems/macros.tex,sha256=0OKG1ZYucoqXPKyX5Xyd2yDJ0CULzXBaf5NXUQa3DfA,617
|
|
22
|
+
notex/templates/problems/preamble.tex,sha256=IFNH8qEnVzgLkKzGgnmYNMelUNpeRxOHc2HbS-Cc_9U,2973
|
|
23
|
+
notex/templates/problems/template.tex,sha256=Sxk9ReAzoC85bL_mXYxDKHu6_qKbliJMUNWiI3GUinw,1288
|
|
24
|
+
notex/templates/single-formulae/letterfonts.tex,sha256=YdNOLBIdK9OVFI7LlPrhefb_g7Qu6FVnXncNpFOjbbg,407
|
|
25
|
+
notex/templates/single-formulae/macros.tex,sha256=tbU3Oq3mYAX9bRgyWOeXHcUvtUy6D8-R4tBLpg1VAmM,565
|
|
26
|
+
notex/templates/single-formulae/preamble.tex,sha256=siGVsCOUncD0v4972Y1JvtRhRLxWBrajvYIiia7uCsI,504
|
|
27
|
+
notex/templates/single-formulae/template.tex,sha256=kX5Xtd7B8ueIpGi2MkA4-l99FcBvRPq_AzyWk_tlVzo,234
|
|
28
|
+
notex/terminal.py,sha256=oA3Ssw2pBcZ4bNbq-Gevef7dHSfbQcGwJzE1JsjZ15o,6165
|
|
29
|
+
notex_cli-0.1.0.dist-info/METADATA,sha256=873eDywfSaho1DMh7Hvg5LRhKg3Xjn8KL3KBRT5ln4I,5677
|
|
30
|
+
notex_cli-0.1.0.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
|
|
31
|
+
notex_cli-0.1.0.dist-info/entry_points.txt,sha256=nfNKBAgmqaOZL6_DkqYiCzrhz-uc6Q4Od_6X9hZrIxQ,57
|
|
32
|
+
notex_cli-0.1.0.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
33
|
+
notex_cli-0.1.0.dist-info/licenses/notex/templates/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
34
|
+
notex_cli-0.1.0.dist-info/RECORD,,
|