From: Jan Szejko Date: Tue, 31 Jul 2018 14:53:56 +0000 (+0200) Subject: pdf: headers, table of contents X-Git-Tag: 1.7~18 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/034fc8488c66a6364ef617e70a5b661591226102?hp=d2cdfb1fd7968f92b9e98cf8f19c7ccf7835d10f pdf: headers, table of contents --- diff --git a/librarian/pdf.py b/librarian/pdf.py index 652d4bf..d67bddf 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -26,7 +26,7 @@ from lxml.etree import XMLSyntaxError, XSLTApplyError from librarian.dcparser import Person from librarian.parser import WLDocument -from librarian import ParseError, DCNS, get_resource, OutputFile +from librarian import ParseError, DCNS, get_resource, OutputFile, RDFNS from librarian import functions from librarian.cover import make_cover from .sponsor import sponsor_logo @@ -110,6 +110,18 @@ def fix_tables(doc): table.set('_format', 'X' * len(table[0])) +def mark_subauthors(doc): + root_author = ', '.join(elem.text for elem in doc.findall('./' + RDFNS('RDF') + '//' + DCNS('creator_parsed'))) + last_author = None + # jeśli autor jest inny niż autor całości i niż poprzedni autor + # to wstawiamy jakiś znacznik w rdf? + for subutwor in doc.xpath('/utwor/utwor'): + author = ', '.join(elem.text for elem in subutwor.findall('.//' + DCNS('creator_parsed'))) + if author not in (last_author, root_author): + subutwor.find('.//' + RDFNS('RDF')).append(etree.Element('use_subauthor')) + last_author = author + + def move_motifs_inside(doc): """ moves motifs to be into block elements """ for master in doc.xpath('//powiesc|//opowiadanie|//liryka_l|//liryka_lp|' @@ -260,6 +272,7 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, substitute_hyphens(document.edoc) fix_hanging(document.edoc) fix_tables(document.edoc) + mark_subauthors(document.edoc) # wl -> TeXML style_filename = get_stylesheet("wl2tex") @@ -315,8 +328,8 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, os.chdir(temp) # some things work better when compiled twice - # but they are not enabled now (line numbers) - for run in xrange(1): + # (table of contents, [line numbers - disabled]) + for run in xrange(2): if verbose: p = call(['xelatex', tex_path]) else: diff --git a/librarian/pdf/wl.cls b/librarian/pdf/wl.cls index cce7d77..153f1a6 100644 --- a/librarian/pdf/wl.cls +++ b/librarian/pdf/wl.cls @@ -60,6 +60,9 @@ \newif\ifenablewlfont \enablewlfonttrue \DeclareOption{nowlfont}{\enablewlfontfalse} +\newif\ifshowtoc \showtoctrue +\DeclareOption{notoc}{\showtocfalse} + \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}} \ProcessOptions\relax \LoadClass[a4paper,oneside]{book} @@ -332,24 +335,42 @@ Letters={Uppercase} } +\DeclareRobustCommand\authortoctext[1]{% +{\addvspace{10pt}\nopagebreak\leftskip0em\relax +\rightskip \@tocrmarg\relax +\noindent\itshape#1\par}} + +\newcommand\authortoc[1]{% + \gdef\chapterauthor{#1}% + \addtocontents{toc}{\authortoctext{#1}}} + + \newcommand{\tytul}[1]{% #1% \vspace{1em}% } -\newcommand{\nazwapodutworu}[1]{% +\newcommand{\nazwapodutworu}[2]{% +\vspace{10ex}% \section*{\typosection{#1}}% +\addcontentsline{toc}{section}{#2}% } \newcommand{\autorutworu}[1]{% \subsection*{\typosubsection{#1}}% } +\newcommand{\autorpodutworu}[1]{% +\subsection*{\typosubsection{#1}}% +\authortoc{#1}% +} + \newcommand{\dzielonadrzedne}[1]{% \subsection*{\typosubsubsection{#1}}% } \newcommand{\nazwautworu}[1]{% +\vspace{10ex}% \section*{\typosection{#1}}% } @@ -371,7 +392,8 @@ Letters={Uppercase} \newcommand{\dramatwspolczesny}[1]{#1} \newcommand{\nota}[1]{% -\par{#1}% +\par{\raggedleft \emph{#1}}% +\vspace{10ex}% } \newcommand{\dedykacja}[1]{% @@ -486,23 +508,31 @@ Letters={Uppercase} \par{#1}% } -\newcommand{\naglowekakt}[1]{% +\newcommand{\naglowekakt}[2]{% \pagebreak -\subsection*{\typosubsection{#1}}% +\subsection*{\typosubsection{\huge #1}}% +\addcontentsline{toc}{subsection}{#2}% +\vspace{10ex}% } -\newcommand{\naglowekczesc}[1]{% +\newcommand{\naglowekczesc}[2]{% \pagebreak -\subsection*{\typosubsection{#1}}% +\subsection*{\typosubsection{\huge #1}}% +\addcontentsline{toc}{subsection}{#2}% +\vspace{10ex}% } \newcommand{\srodtytul}[1]{% \subsection*{\typosubsection{#1}}% } -\newcommand{\naglowekscena}[1]{% -\subsubsection*{\typosubsubsection{#1}}% +\newcommand{\naglowekscena}[2]{% +\subsubsection*{\typosubsubsection{\LARGE #1}}% +\addcontentsline{toc}{subsubsection}{#2}% +\vspace{5ex}% } -\newcommand{\naglowekrozdzial}[1]{% -\subsubsection*{\typosubsubsection{#1}}% +\newcommand{\naglowekrozdzial}[2]{% +\subsubsection*{\typosubsubsection{\LARGE #1}}% +\addcontentsline{toc}{subsubsection}{#2}% +\vspace{5ex}% } \newcommand{\naglowekosoba}[1]{% @@ -611,7 +641,7 @@ Letters={Uppercase} } \newcommand{\osoba}[1]{% -{\textsc{#1}}% +{\scshape \MakeLowercase{#1}}% } \newcommand{\sekcjaswiatlo}{% diff --git a/librarian/pdf/wl2tex.xslt b/librarian/pdf/wl2tex.xslt index 970c175..6c60125 100644 --- a/librarian/pdf/wl2tex.xslt +++ b/librarian/pdf/wl2tex.xslt @@ -89,6 +89,16 @@ + + + + tocdepth + 3 + + + + + @@ -141,7 +151,7 @@ - + @@ -221,6 +231,9 @@ + + + @@ -295,9 +308,36 @@ + + + + + + + + + + + + + + - + + + + + + + + + + + + + + match="naglowek_osoba|naglowek_podrozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_diafrlog|akap_cd|motto_podpis|naglowek_listy|srodtytul"> @@ -306,6 +346,20 @@ + + + + + + + + + + + + + + t @@ -432,6 +486,13 @@ + + + , + + + + Opracowanie redakcyjne i przypisy: