pdf: headers, table of contents
authorJan Szejko <janek37@gmail.com>
Tue, 31 Jul 2018 14:53:56 +0000 (16:53 +0200)
committerJan Szejko <janek37@gmail.com>
Tue, 31 Jul 2018 14:53:56 +0000 (16:53 +0200)
librarian/pdf.py
librarian/pdf/wl.cls
librarian/pdf/wl2tex.xslt

index 652d4bf..d67bddf 100644 (file)
@@ -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:
index cce7d77..153f1a6 100644 (file)
@@ -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}{%
index 970c175..6c60125 100644 (file)
                 </xsl:otherwise>
               </xsl:choose>
             </parm></cmd>
+            <xsl:if test="//utwor//utwor or //naglowek_czesc or //naglowek_akt or //srodtytul or //naglowek_scena or //naglowek_rozdzial">
+                <cmd name="ifshowtoc" />
+                <cmd name="setcounter" >
+                    <parm>tocdepth</parm>
+                    <parm>3</parm>
+                </cmd>
+                <cmd name="tableofcontents" />
+                <cmd name="clearpage" />
+                <cmd name="fi" />
+            </xsl:if>
             <xsl:apply-templates select="powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny" />
             <xsl:apply-templates select="utwor" mode="part" />
 
       <xsl:choose>
         <xsl:when test="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu">
             <!-- title in master -->
-            <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="title" />
+            <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/nazwa_utworu" mode="part_title" />
             <xsl:apply-templates select="(powiesc|opowiadanie|liryka_l|liryka_lp|dramat_wierszowany_l|dramat_wierszowany_lp|dramat_wspolczesny)/podtytul" mode="title" />
         </xsl:when>
         <xsl:otherwise>
 </xsl:template>
 
 <xsl:template match="rdf:RDF" mode="dctitle">
+    <cmd name="autorpodutworu">
+        <parm><xsl:call-template name="authors" /></parm>
+    </cmd>
     <cmd name="nazwapodutworu"><parm>
         <xsl:apply-templates select=".//dc:title/node()" mode="inline" />
     </parm></cmd>
     </cmd>
 </xsl:template>
 
+<xsl:template match="nazwa_utworu" mode="part_title">
+    <xsl:if test="../../rdf:RDF//use_subauthor">
+        <cmd name="autorpodutworu"><parm><xsl:call-template name="authors2"/></parm></cmd>
+    </xsl:if>
+    <cmd name="nazwapodutworu">
+        <parm><xsl:apply-templates mode="inline"/></parm>
+        <parm>
+            <xsl:for-each select="./text() | nbsp | dywiz | alien">
+                <xsl:choose>
+                    <xsl:when test="name() = 'nbsp'">
+                        <xsl:text> </xsl:text>
+                    </xsl:when>
+                    <xsl:when test="name() = 'dywiz'">
+                        <xsl:text>-</xsl:text>
+                    </xsl:when>
+                    <xsl:when test="name() = 'alien'">
+                        <xsl:apply-templates mode="inline" />
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:value-of select="."/>
+                    </xsl:otherwise>
+                </xsl:choose>
+            </xsl:for-each>
+        </parm>
+    </cmd>
+</xsl:template>
+
 
 <xsl:template
-    match="naglowek_akt|naglowek_czesc|srodtytul|naglowek_osoba|naglowek_podrozdzial|naglowek_scena|naglowek_rozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_dialog|akap_cd|motto_podpis|naglowek_listy">
+    match="naglowek_osoba|naglowek_podrozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_diafrlog|akap_cd|motto_podpis|naglowek_listy|srodtytul">
     <cmd>
         <xsl:attribute name="name">
             <xsl:value-of select="wl:texcommand(name())" />
     </cmd>
 </xsl:template>
 
+<xsl:template match="naglowek_czesc|naglowek_rozdzial|naglowek_akt|naglowek_scena">
+    <cmd>
+        <xsl:attribute name="name">
+            <xsl:value-of select="wl:texcommand(name())" />
+        </xsl:attribute>
+        <parm><xsl:apply-templates mode="inline"/></parm>
+        <parm>
+            <xsl:for-each select="./text()">
+                <xsl:value-of select="."/>
+            </xsl:for-each>
+        </parm>
+    </cmd>
+</xsl:template>
+
 <xsl:template match="strofa" mode="inline">
     <env name="minipage">
         <opt>t</opt>
     </xsl:for-each>
 </xsl:template>
 
+<xsl:template name="authors2">
+    <xsl:for-each select="../..//dc:creator_parsed">
+        <xsl:if test="position() != 1">, </xsl:if>
+        <xsl:apply-templates mode="inline" />
+    </xsl:for-each>
+</xsl:template>
+
 <xsl:template name="editors">
     <xsl:if test="@editors">
         <xsl:text>Opracowanie redakcyjne i przypisy: </xsl:text>