aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/out_latex.org
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2022-03-24 12:38:41 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2022-04-03 18:13:50 -0400
commite2424c06d3bfa552f35fb288429c3ef4e5357cc7 (patch)
treec1d8aefd2ce9acc7760a4eb9dbef1eea3afa3c66 /org/out_latex.org
parentlatex, pagebreaks, make headers, consider (diff)
latex output (try tidy); linebreaks more generally
Diffstat (limited to 'org/out_latex.org')
-rw-r--r--org/out_latex.org199
1 files changed, 134 insertions, 65 deletions
diff --git a/org/out_latex.org b/org/out_latex.org
index af17d60..bac3158 100644
--- a/org/out_latex.org
+++ b/org/out_latex.org
@@ -39,6 +39,7 @@ template outputLaTeX() {
<<output_latex_shared_fontface>>
<<output_latex_shared_leading_hardspaces>>
<<output_latex_shared_character_nbsp_to_hardspace>>
+ <<output_latex_shared_character_spaces_to_hardspace>>
<<output_latex_shared_character_nbsp_to_space>>
<<output_latex_shared_links_and_images>>
<<output_latex_shared_footnotes>>
@@ -547,7 +548,7 @@ _txt = _txt
#+END_SRC
**** spaces
-***** leading hardspace
+***** leading hardspace UNUSED
#+NAME: output_latex_shared_leading_hardspaces
#+BEGIN_SRC d
@@ -556,7 +557,7 @@ _txt = _txt
) {
string hardspaces(string _spaces) {
_spaces = _spaces
- .replaceAll(rgx.space, "\\hardspace ");
+ .replaceAll(rgx.space, "{\\s}");
return _spaces;
}
_txt = replaceAll!(m => hardspaces(m[0]))(_txt, rgx.spaces_line_start);
@@ -564,13 +565,49 @@ _txt = _txt
}
#+END_SRC
+***** nbsp character UNUSED
+
+#+NAME: output_latex_shared_character_nbsp_to_hardspace_
+#+BEGIN_SRC d
+@safe string nbsp_char_replace()(string _txt) {
+ if (_txt.match(rgx.nbsp_char)) {
+ _txt = _txt.replaceAll(rgx.nbsp_char, "{\\s}");
+ }
+ return _txt;
+}
+#+END_SRC
+
***** nbsp character
#+NAME: output_latex_shared_character_nbsp_to_hardspace
#+BEGIN_SRC d
@safe string nbsp_char()(string _txt) {
if (_txt.match(rgx.nbsp_char)) {
- _txt = _txt.replaceAll(rgx.nbsp_char, "\\hardspace ");
+ foreach (m; _txt.matchAll(rgx.nbsp_chars)) {
+ int spaces_ = 0;
+ foreach (n; m[0].matchAll(rgx.nbsp_char)) {
+ spaces_ ++;
+ }
+ _txt = _txt.replaceFirst(rgx.nbsp_chars, "\\spaces{" ~ spaces_.to!string ~ "}");
+ }
+ }
+ return _txt;
+}
+#+END_SRC
+
+***** keep spaces
+
+#+NAME: output_latex_shared_character_spaces_to_hardspace
+#+BEGIN_SRC d
+@safe string spaces_to_nbsp()(string _txt) {
+ if (_txt.match(rgx.spaces_keep)) {
+ foreach (m; _txt.matchAll(rgx.spaces_keep)) {
+ int spaces_ = 0;
+ foreach (n; m[0].matchAll(rgx.space)) {
+ spaces_ ++;
+ }
+ _txt = _txt.replaceFirst(rgx.spaces_keep, "\\spaces{" ~ spaces_.to!string ~ "}");
+ }
}
return _txt;
}
@@ -631,9 +668,9 @@ _txt = _txt
((m[1] == m[2]) && (m[2].match(rgx.uri))) // url link (regular link with url)
? format(q"┃\linkurl{%s}{%s}┃", _check_link(m[1]), (_check_link(m[1])).sp_char_esc_txt)
: ((m[2].match(rgx.uri)) && (m[1].match(rgx.inline_image_info))) // linked image
- ? format(q"┃%s\href{%s}%s{%s}┃", "\\br\n", _check_link(m[2]), "\n", _if_images(m[1])) // markup for images
+ ? format(q"┃%s\href{%s}%s{%s}┃", "\\br ", _check_link(m[2]), "\n", _if_images(m[1])) // markup for images
: (m[2].match(rgx.uri)) // not linked image
- ? format(q"┃%s\linktext{%s}{%s}┃", "\\br\n", _check_link(m[2]), m[1]) // regular link with text
+ ? format(q"┃%s\linktext{%s}{%s}┃", "\\br ", _check_link(m[2]), m[1]) // regular link with text
: format(q"┃\hyperlink{%s}{%s}┃", _check_link(m[2]), _if_images(m[1])) // internal links, like book index
)(_txt, rgx.inline_link);
}
@@ -653,7 +690,7 @@ _txt = _txt
if (_txt.match(rgx.inline_notes_al_gen)) {
string _tex_note = q"┃\hypertarget{noteref_%s}{}\footnote[%s]{%%
\label{note_%s}%s}┃";
- _txt = _txt.replaceAll(rgx.inline_notes_al_regular_number_note,
+ _txt = _txt.split(rgx.br_linebreaks).join("\\br ").replaceAll(rgx.inline_notes_al_regular_number_note,
format(_tex_note,
"$1", "$1", "$1",
"$2".strip
@@ -713,7 +750,7 @@ _txt = _txt
string _tex_para;
_tex_para = q"┃%s┃";
_txt = format(_tex_para,
- _txt.replaceAll(rgx.latex_clean_bookindex_linebreak, "\n") ~ "\n\\br\n"
+ _txt.replaceAll(rgx.latex_clean_bookindex_linebreak, "\n") ~ "\n\\brln\n"
);
}
return _txt;
@@ -735,7 +772,7 @@ _txt = _txt
if (obj.attrib.bullet) {
int _bullet_space = 5;
_indent = ((obj.attrib.indent_base * _indent_increment) + _paper_margin + _bullet_space).to!string;
- _txt = format(q"┃\begin{Bullet}{%smm}$\txtbullet$\hspace{\enspace}%s\end{Bullet}┃",
+ _txt = format(q"┃\begin{Bullet}{%smm}%s\end{Bullet}┃",
_indent,
_txt.footnotes
).strip;
@@ -758,7 +795,7 @@ _txt = _txt
_tex_para = q"┃\begin{ParagraphHang}{%smm}{%smm}%s \end{ParagraphHang}┃";
_txt = format(_tex_para,
_indent, _hang,
- _txt.footnotes
+ _txt.footnotes.split(rgx.br_linebreaks_newlines).join("\\br\n")
).strip;
}
return _txt;
@@ -973,7 +1010,6 @@ _txt = _txt
\pagenumbering{arabic}
\setcounter{page}{1}
\markboth{ }{ }
-\setlength{\parskip}{1ex plus0.5ex minus0.2ex}
\part*{\ocn{1}%s \newline %s}
\clearpage
@@ -1053,14 +1089,14 @@ string group(O,M)(
) {
if (obj.metainfo.is_a == "group") {
string _tex_para;
- _tex_para = q"┃\ocn{%s}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}
-\begin{footnotesize}
+ _tex_para = q"┃\ocn{%s}\objGroupOpen
%s
-\end{footnotesize}
+\objGroupClose
┃";
_txt = format(_tex_para,
obj.metainfo.object_number,
- _txt.footnotes.strip
+ _txt.footnotes.split(rgx.br_line_spaced).join("\\brl{1}").strip // provides more control (more noise, not as tidy)
+ // _txt.footnotes.split(rgx.br_line_spaced).join("") // this works using a line-space, looks tidy, keep ref.
).strip;
}
return _txt;
@@ -1079,26 +1115,21 @@ string block(O,M)(
M doc_matters,
) {
if (obj.metainfo.is_a == "block") {
- // _txt = _txt.nbsp_char;
string _tex_para;
- _tex_para = q"┃\ocn{%s}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}
-\begin{footnotesize}
+ _tex_para = q"┃\ocn{%s}\objBlockOpen
%s
-\end{footnotesize}
-\setlength{\parskip}{1ex plus0.5ex minus0.2ex}
-┃"; // \hardspace
- /+ try both: +/
- _txt = _txt.split(rgx.br_newlines_linebreaks).join("\n\n"); // _txt = _txt.split(rgx.br_newlines_linebreaks).join(" \\\n");
- _txt = format(_tex_para,
+\objBlockClose
+┃";
+ _txt = format(_tex_para,
obj.metainfo.object_number,
- _txt.nbsp_char.footnotes.strip
+ _txt.nbsp_char.footnotes.split(rgx.br_linebreaks_newlines).join("\\br\n").strip
).strip;
}
return _txt;
}
#+END_SRC
-**** verse
+**** (poem) verse
- (hardspace honored) \hardspace
@@ -1111,18 +1142,13 @@ string verse(O,M)(
) {
if (obj.metainfo.is_a == "verse") {
string _tex_para;
- _tex_para = q"┃\ocn{%s}\setlength{\parskip}{0.1ex plus0.1ex minus0.1ex}
-\begin{footnotesize}
-
+ _tex_para = q"┃\ocn{%s}\objPoemVerseOpen
%s
-
-\end{footnotesize}
-\setlength{\parskip}{1ex plus0.5ex minus0.2ex}
-\linebreak
-┃"; // \hardspace
+\objPoemVerseClose
+┃";
_txt = format(_tex_para,
obj.metainfo.object_number,
- _txt.nbsp_char.footnotes.split("\n").join("\n\n").strip
+ _txt.spaces_to_nbsp.footnotes.split(rgx.br_linebreaks_newlines).join("\\br\n").strip
).strip;
}
return _txt;
@@ -1142,12 +1168,9 @@ string codeblock(O,M)(
) {
if (obj.metainfo.is_a == "code") {
string _tex_para;
- _tex_para = q"┃\ocn{%s}\setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}\begin{Codeblock}
-\begin{lstlisting}
+ _tex_para = q"┃\ocn{%s}\begin{objCodeBlock}\begin{lstlisting}
%s
-\end{lstlisting}
-\end{Codeblock}
-\setlength{\parskip}{1ex plus0.5ex minus0.2ex}
+\end{lstlisting}\end{objCodeBlock}
┃";
_txt = format(_tex_para,
obj.metainfo.object_number,
@@ -1239,14 +1262,9 @@ string table(O,M)(
);
}
string _tex_para;
- _tex_para = q"┃\ocn{%s}
-\setlength{\LTleft}{0pt}
-\setlength{\LTright}{\fill}
-\begin{tiny}
-\begin{longtable}{%s}
+ _tex_para = q"┃\ocn{%s}\objTableOpen{%s}
%s
-\end{longtable}
-\end{tiny}
+\objTableClose
┃";
_txt = format(_tex_para,
obj.metainfo.object_number,
@@ -1700,7 +1718,7 @@ string _latex_head = format(q"┃%%%% spine LaTeX output
\usepackage[tc]{titlepic}
\usepackage{graphicx}
\makeatletter
-\parindent0pt
+\parindent{0pt}
\usepackage{amssymb}
\usepackage{listings}
\usepackage{color}
@@ -1748,6 +1766,7 @@ string _latex_head = format(q"┃%%%% spine LaTeX output
\setlength\parsep{0pt plus 1pt}%%
}
\item[]
+$\txtbullet$\hspace{\enspace}
}
{\end{list}}
#+END_SRC
@@ -1781,16 +1800,52 @@ string _latex_head = format(q"┃%%%% spine LaTeX output
\chardef\tilde="7E
\def\asterisk{{\rm \char42} }
\definecolor{Light}{gray}{.92}
-\newcommand{\Codeblock}[1]{\normaltext\raggedright\small\ttfamily\texbackslash#1}
\newcommand{\monosp}[1]{\normaltext\ttfamily\texbackslash#1}
+\newcommand{\br}{\hfill\break}
+\newcommand{\brl}[1]{%%
+ \ifx&#1&%%
+ \hfill\break
+ \else
+ \vspace{#1ex}
+ \fi
+}
+\newcommand{\brln}{\hspace*{\fill}\linebreak}
+\newcomand{\objBlockOpen}{
+ \setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}\raggedright
+ \begin{footnotesize}
+}
+\newcomand{\objBlockClose}{%%
+ \end{footnotesize}
+ \setlength{\parskip}{1ex plus0.5ex minus0.2ex}
+}
+\newcomand{\objGroupOpen}{%%
+ \setlength{\parskip}{0.5ex plus0.2ex minus0.1ex}
+ \begin{footnotesize}
+}
+\newcomand{\objGroupClose}{%%
+ \end{footnotesize}
+}
+\newcommand{\objPoemVerseOpen}{%%
+ \setlength{\parskip}{0.1ex plus0.1ex minus0.1ex}
+ \begin{footnotesize}
+
+}
+\newcommand{\objPoemVerseClose}{%%
+
+ \end{footnotesize}
+ \setlength{\parskip}{1ex plus0.5ex minus0.2ex}
+ \linebreak
+}
\newcommand{\parasep}{\smallskip \begin{center}*\hspace{2em}*\hspace{2em}*\end{center} \br}
-\newcommand{\br}{\hspace*{\fill}}
-\newcommand{\brln}{\smallskip}
-\newcommand{\hardspace}{{~}}
+\newcommand{\spaces}[1]{{\hspace*{#1ex}}}
+\newcommand{\s}{\hspace*{1ex}}
+\newcommand{\hardspace}{\hspace*{1ex}}
+\newcommand{\-}{\hspace*{1ex}}
+\newcommand{\..}{\hspace*{1ex}} %% dots trailing
\newcommand{\caret}{{\^{~}}}
\newcommand{\pipe}{{\textbar}}
-\newcommand{\curlyopen}{{}
-\newcommand{\curlyclose}{}}
+\newcommand{\curlyOpen}{{}
+\newcommand{\curlyClose}{}}
\newcommand{\lt}{{UseTextSymbol{OML}{<}}}
\newcommand{\gt}{{UseTextSymbol{OML}{>}}}
\newcommand{\slash}{{/}}
@@ -1802,18 +1857,27 @@ string _latex_head = format(q"┃%%%% spine LaTeX output
{\scriptsize\ttfamily\ulcorner\textup{{#2}}\lrcorner}}}
\newcommand{\link}[2]{{\begin{scriptsize}\color{black}\urlstyle{tt}\href{#1}
{\ulcorner{#2}\lrcorner}\end{scriptsize}}}
+\newcommand{\objCodeBlock}[1]{\normaltext\raggedright\small\ttfamily\texbackslash#1}
+\newcommand{\objCodeOpen}{\normaltext\raggedright\small\ttfamily\texbackslash
+\begin{lstlisting}
+}
+\newcommand{\objCodeClose}{
+\end{lstlisting}
+}
\newcommand{\ocn}[1]{%%
+ \setlength{\parindent}{0em}
\ifx&#1&%%
%% #1 is empty
- \begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\end{tiny}}}
+ \hspace{-0.5ex}{\marginpar{\begin{tiny}\end{tiny}}}
\else
%% #1 is nonempty
- \begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{#1}{#1}\end{tiny}}}
+ \hspace{-0.5ex}{\marginpar{\begin{tiny}\hspace{0em}\hypertarget{#1}{#1}\end{tiny}}}
\fi
}
\newcommand{\ocnhold}[1]{
\begin{tiny}\hspace{0mm}\end{tiny}{\marginpar{\begin{tiny}\hspace{0mm}\hypertarget{#1}{#1}\end{tiny}}}
}
+\newcommand{\objCodeBlockHold}[1]{\normaltext\raggedright\small\ttfamily\texbackslash#1}
\definecolor{listinggray}{gray}{0.9}
\definecolor{lbcolor}{rgb}{0.9,0.9,0.9}
\lstset{
@@ -1821,9 +1885,8 @@ string _latex_head = format(q"┃%%%% spine LaTeX output
tabsize=4,
rulecolor=,
language=,
- basicstyle=\scriptsize,
+ basicstyle={\ttfamily\scriptsize},
upquote=true,
- aboveskip={1.5\baselineskip},
columns=fixed,
showstringspaces=false,
extendedchars=true,
@@ -1838,6 +1901,16 @@ string _latex_head = format(q"┃%%%% spine LaTeX output
commentstyle=\color[rgb]{0.133,0.545,0.133},
stringstyle=\color[rgb]{0.627,0.126,0.941},
}
+\newcommand{\objTableOpen}[1]{
+\setlength{\LTleft}{0pt}
+\setlength{\LTright}{\fill}
+\begin{tiny}
+\begin{longtable}{#1}
+}
+\newcommand{\objTableClose}{
+\end{longtable}
+\end{tiny}
+}
#+END_SRC
%%\chardef\asterisk="2A
@@ -1956,23 +2029,19 @@ case "body": assert(part == "body" || "head"); // surprise
switch (obj.metainfo.is_a) {
case "quote":
goto default; // TODO
- case "group":
- /+ (hardspaces not honored) [remove any hardspace marker] +/
+ case "group": /+ (hardspaces not honored) [remove any hardspace marker] +/
_txt = _txt.group(obj, doc_matters)
.links_and_images(obj, doc_matters);
goto default;
- case "block":
- /+ (hardspace honored) \hardspace +/
+ case "block": /+ (hardspace honored) \hardspace +/
_txt = _txt.block(obj, doc_matters)
.links_and_images(obj, doc_matters);
goto default;
- case "verse":
- /+ (hardspace honored) \hardspace +/
+ case "verse": /+ (hardspace honored) \hardspace +/
_txt = _txt.verse(obj, doc_matters)
.links_and_images(obj, doc_matters);
goto default;
- case "code":
- /+ (hardspace honored) \begin{lstlisting} clear hardspace marker +/
+ case "code": /+ (hardspace honored) \begin{lstlisting} clear hardspace marker +/
_txt = _txt.codeblock(obj, doc_matters);
goto default;
case "table":