Browse Source

Generated LaTeX file contains nicer spaces

No weird indentation, no trailing whitespaces, no long long paragraph breaks (one line or two are sufficient), etc.
pull/79/head
Louis 10 years ago
parent
commit
ea1b382f5f
  1. 1
      patacrep/data/examples/example-all.sb
  2. 119
      patacrep/data/templates/default.tex
  3. 56
      patacrep/data/templates/layout.tex
  4. 111
      patacrep/data/templates/patacrep.tex
  5. 99
      patacrep/data/templates/songs.tex
  6. 21
      patacrep/songs/chordpro/data/latex/chordpro.tex
  7. 4
      patacrep/songs/chordpro/data/latex/content_line.tex
  8. 3
      patacrep/songs/chordpro/data/latex/content_verse.tex
  9. 32
      patacrep/templates.py

1
patacrep/data/examples/example-all.sb

@ -6,6 +6,7 @@
"pictures" "pictures"
], ],
"booktype" : "chorded", "booktype" : "chorded",
"template" : "patacrep.tex",
"lang" : "french", "lang" : "french",
"encoding": "utf8", "encoding": "utf8",
"authwords" : { "authwords" : {

119
patacrep/data/templates/default.tex

@ -1,23 +1,22 @@
%! Copyright (C) 2014 The Patacrep team (www.patacrep.com) %!- Copyright (C) 2014 The Patacrep team (www.patacrep.com)
%! %!-
%! This program is free software; you can redistribute it and/or %!- This program is free software; you can redistribute it and/or
%! modify it under the terms of the GNU General Public License %!- modify it under the terms of the GNU General Public License
%! as published by the Free Software Foundation; either version 2 %!- as published by the Free Software Foundation; either version 2
%! of the License, or (at your option) any later version. %!- of the License, or (at your option) any later version.
%! %!-
%! This program is distributed in the hope that it will be useful, %!- This program is distributed in the hope that it will be useful,
%! but WITHOUT ANY WARRANTY; without even the implied warranty of %!- but WITHOUT ANY WARRANTY; without even the implied warranty of
%! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %!- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%! GNU General Public License for more details. %!- GNU General Public License for more details.
%! %!-
%! You should have received a copy of the GNU General Public License %!- You should have received a copy of the GNU General Public License
%! along with this program; if not, write to the Free Software %!- along with this program; if not, write to the Free Software
%! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, %!- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
%! MA 02110-1301, USA. %!- MA 02110-1301, USA.
%! %!-
%! The latest version of this program can be obtained from %!- The latest version of this program can be obtained from
%! https://github.com/patacrep/ %!- https://github.com/patacrep/
(* variables *) (* variables *)
{ {
@ -40,47 +39,49 @@
"default": {"default": "alphascale", "french": "solfedge"} "default": {"default": "alphascale", "french": "solfedge"}
} }
} }
(* endvariables *) (* endvariables -*)
(* extends "songs.tex" *) (*- extends "songs.tex" -*)
(* set indexes = "titleidx,authidx" *) (*- set indexes = "titleidx,authidx" -*)
(* block documentclass *) (* block documentclass *)
\documentclass[(* for option in classoptions *) \documentclass[
((option)), (* for option in classoptions *)
(* endfor *)]{article} ((option)),
(* endfor *)
]{article}
(* endblock *) (* endblock *)
(* block songbookpreambule *) (* block songbookpreambule *)
(( super() )) (( super() ))
\usepackage{chords} \usepackage{chords}
\title{((title))} \title{((title))}
\author{((author))} \author{((author))}
\newindex{titleidx}{((filename))_title} \newindex{titleidx}{((filename))_title}
\newauthorindex{authidx}{((filename))_auth} \newauthorindex{authidx}{((filename))_auth}
(* for prefix in titleprefixwords *) (* for prefix in titleprefixwords -*)
\titleprefixword{((prefix))} \titleprefixword{((prefix))}
(* endfor*) (* endfor*)
(* for word in authwords.ignore *) (* for word in authwords.ignore -*)
\authignoreword{((word))} \authignoreword{((word))}
(* endfor *) (* endfor *)
(* for word in authwords.after *) (* for word in authwords.after -*)
\authbyword{((word))} \authbyword{((word))}
(* endfor *) (* endfor *)
(* for word in authwords.sep *) (* for word in authwords.sep -*)
\authsepword{((word))} \authsepword{((word))}
(* endfor *) (* endfor *)
(* if notenamesout=="alphascale" *) (* if notenamesout=="alphascale" -*)
\notenamesout{A}{B}{C}{D}{E}{F}{G} \notenamesout{A}{B}{C}{D}{E}{F}{G}
(* else *) (* else -*)
\notenamesout{La}{Si}{Do}{R\'e}{Mi}{Fa}{Sol} \notenamesout{La}{Si}{Do}{R\'e}{Mi}{Fa}{Sol}
(* endif *) (* endif *)
(* endblock *) (* endblock *)
(* block title *) (* block title *)
@ -88,18 +89,18 @@
(* endblock *) (* endblock *)
(* block index *) (* block index *)
\showindex{\songindexname}{titleidx} \showindex{\songindexname}{titleidx}
\showindex{\authorindexname}{authidx} \showindex{\authorindexname}{authidx}
(* endblock *) (* endblock *)
(* block chords *) (* block chords *)
% list of chords % list of chords
\ifchorded \ifchorded
\ifdiagram \ifdiagram
\phantomsection \phantomsection
\addcontentsline{toc}{section}{\chordlistname} \addcontentsline{toc}{section}{\chordlistname}
\chords \chords
\fi \fi
\fi \fi
(* endblock *) (* endblock *)

56
patacrep/data/templates/layout.tex

@ -1,23 +1,22 @@
%! Copyright (C) 2014 The Patacrep team (www.patacrep.com) %!- Copyright (C) 2014 The Patacrep team (www.patacrep.com)
%! %!-
%! This program is free software; you can redistribute it and/or %!- This program is free software; you can redistribute it and/or
%! modify it under the terms of the GNU General Public License %!- modify it under the terms of the GNU General Public License
%! as published by the Free Software Foundation; either version 2 %!- as published by the Free Software Foundation; either version 2
%! of the License, or (at your option) any later version. %!- of the License, or (at your option) any later version.
%! %!-
%! This program is distributed in the hope that it will be useful, %!- This program is distributed in the hope that it will be useful,
%! but WITHOUT ANY WARRANTY; without even the implied warranty of %!- but WITHOUT ANY WARRANTY; without even the implied warranty of
%! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %!- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%! GNU General Public License for more details. %!- GNU General Public License for more details.
%! %!-
%! You should have received a copy of the GNU General Public License %!- You should have received a copy of the GNU General Public License
%! along with this program; if not, write to the Free Software %!- along with this program; if not, write to the Free Software
%! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, %!- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
%! MA 02110-1301, USA. %!- MA 02110-1301, USA.
%! %!-
%! The latest version of this program can be obtained from %!- The latest version of this program can be obtained from
%! https://github.com/patacrep/ %!- https://github.com/patacrep/
%% Automatically generated document. %% Automatically generated document.
%% You may edit this file but all changes will be overwritten. %% You may edit this file but all changes will be overwritten.
@ -27,10 +26,11 @@
%% Generated using Songbook <http://www.patacrep.com> %% Generated using Songbook <http://www.patacrep.com>
\makeatletter \makeatletter
\def\input@path{(* for dir in datadir *) \def\input@path{ %
{(( path2posix(dir) ))/latex/} % (* for dir in datadir *)
(* endfor *) {(( path2posix(dir) ))/latex/} %
} (* endfor *)
}
\makeatother \makeatother
(* block documentclass *) (* block documentclass *)
@ -41,9 +41,9 @@
(* endblock *) (* endblock *)
(* block songbookpreambule *) (* block songbookpreambule *)
\usepackage[utf8]{inputenc} \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc} \usepackage[T1]{fontenc}
\usepackage{lmodern} \usepackage{lmodern}
(* endblock songbookpreambule *) (* endblock songbookpreambule *)
(* block preambule *) (* block preambule *)
@ -71,4 +71,4 @@
\end{document} \end{document}
%! End of file %!- End of file

111
patacrep/data/templates/patacrep.tex

@ -1,23 +1,22 @@
%! Copyright (C) 2014 The Patacrep team (www.patacrep.com) %!- Copyright (C) 2014 The Patacrep team (www.patacrep.com)
%! %!-
%! This program is free software; you can redistribute it and/or %!- This program is free software; you can redistribute it and/or
%! modify it under the terms of the GNU General Public License %!- modify it under the terms of the GNU General Public License
%! as published by the Free Software Foundation; either version 2 %!- as published by the Free Software Foundation; either version 2
%! of the License, or (at your option) any later version. %!- of the License, or (at your option) any later version.
%! %!-
%! This program is distributed in the hope that it will be useful, %!- This program is distributed in the hope that it will be useful,
%! but WITHOUT ANY WARRANTY; without even the implied warranty of %!- but WITHOUT ANY WARRANTY; without even the implied warranty of
%! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %!- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%! GNU General Public License for more details. %!- GNU General Public License for more details.
%! %!-
%! You should have received a copy of the GNU General Public License %!- You should have received a copy of the GNU General Public License
%! along with this program; if not, write to the Free Software %!- along with this program; if not, write to the Free Software
%! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, %!- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
%! MA 02110-1301, USA. %!- MA 02110-1301, USA.
%! %!-
%! The latest version of this program can be obtained from %!- The latest version of this program can be obtained from
%! https://github.com/patacrep/ %!- https://github.com/patacrep/
(* variables *) (* variables *)
{ {
@ -61,21 +60,25 @@
"Des", "El", "Les", "Ma", "Mon", "Un"]} "Des", "El", "Les", "Ma", "Mon", "Un"]}
} }
} }
(* endvariables *) (* endvariables -*)
(* extends "default.tex" *) (*- extends "default.tex" -*)
(* block songbookpackages *) (* block songbookpackages *)
%! booktype, bookoptions and instruments are defined in "songs.tex" %! booktype, bookoptions and instruments are defined in "songs.tex"
\usepackage[((booktype)), \usepackage[
(* for option in bookoptions *)((option)), ((booktype)),
(* endfor *) (* for option in bookoptions *)
(* for instrument in instruments *)((instrument)), ((option)),
(* endfor *)]{crepbook} (* endfor *)
(* for instrument in instruments *)
((instrument)),
(* endfor *)
]{crepbook}
(* endblock *) (* endblock *)
(* block songbookpreambule *) (* block songbookpreambule *)
\usepackage[ \usepackage[
a4paper % paper size a4paper % paper size
,includeheadfoot % include header and footer into text size ,includeheadfoot % include header and footer into text size
,hmarginratio=1:1 % ratio between inner and outer margin (default) ,hmarginratio=1:1 % ratio between inner and outer margin (default)
@ -84,35 +87,37 @@
,bmargin=1.3cm % bottom margin ,bmargin=1.3cm % bottom margin
]{geometry} ]{geometry}
(( super() )) (( super() ))
\pagestyle{empty} \pagestyle{empty}
\definecolor{SongNumberBgColor}{HTML}{((songnumberbgcolor))} \definecolor{SongNumberBgColor}{HTML}{((songnumberbgcolor))}
\definecolor{NoteBgColor}{HTML}{((notebgcolor))} \definecolor{NoteBgColor}{HTML}{((notebgcolor))}
\definecolor{IndexBgColor}{HTML}{((indexbgcolor))} \definecolor{IndexBgColor}{HTML}{((indexbgcolor))}
\renewcommand{\snumbgcolor}{SongNumberBgColor} \renewcommand{\snumbgcolor}{SongNumberBgColor}
\renewcommand{\notebgcolor}{NoteBgColor} \renewcommand{\notebgcolor}{NoteBgColor}
\renewcommand{\idxbgcolor}{IndexBgColor} \renewcommand{\idxbgcolor}{IndexBgColor}
\definecolor{tango-green-3}{HTML}{4e9a06} \definecolor{tango-green-3}{HTML}{4e9a06}
\definecolor{tango-blue-3}{HTML}{204a87} \definecolor{tango-blue-3}{HTML}{204a87}
\usepackage[bookmarks, \usepackage[
bookmarksopen, bookmarks,
hyperfigures=true, bookmarksopen,
colorlinks=true, hyperfigures=true,
linkcolor=tango-green-3, colorlinks=true,
urlcolor=tango-blue-3]{hyperref} linkcolor=tango-green-3,
urlcolor=tango-blue-3
]{hyperref}
\subtitle{((subtitle))} \subtitle{((subtitle))}
(* if version!="undefined" *) (* if version!="undefined" -*)
\version{((version))} \version{((version))}
(* endif *) (* endif *)
\mail{((mail))} \mail{((mail))}
\web{((web))} \web{((web))}
\picture{((picture))} \picture{((picture))}
\picturecopyright{((picturecopyright))} \picturecopyright{((picturecopyright))}
\footer{((footer))} \footer{((footer))}
(* endblock *) (* endblock *)

99
patacrep/data/templates/songs.tex

@ -1,22 +1,22 @@
%! Copyright (C) 2014 The Patacrep team (www.patacrep.com) %!- Copyright (C) 2014 The Patacrep team (www.patacrep.com)
%! %!-
%! This program is free software; you can redistribute it and/or %!- This program is free software; you can redistribute it and/or
%! modify it under the terms of the GNU General Public License %!- modify it under the terms of the GNU General Public License
%! as published by the Free Software Foundation; either version 2 %!- as published by the Free Software Foundation; either version 2
%! of the License, or (at your option) any later version. %!- of the License, or (at your option) any later version.
%! %!-
%! This program is distributed in the hope that it will be useful, %!- This program is distributed in the hope that it will be useful,
%! but WITHOUT ANY WARRANTY; without even the implied warranty of %!- but WITHOUT ANY WARRANTY; without even the implied warranty of
%! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %!- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%! GNU General Public License for more details. %!- GNU General Public License for more details.
%! %!-
%! You should have received a copy of the GNU General Public License %!- You should have received a copy of the GNU General Public License
%! along with this program; if not, write to the Free Software %!- along with this program; if not, write to the Free Software
%! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, %!- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
%! MA 02110-1301, USA. %!- MA 02110-1301, USA.
%! %!-
%! The latest version of this program can be obtained from %!- The latest version of this program can be obtained from
%! https://github.com/patacrep/ %!- https://github.com/patacrep/
(* variables *) (* variables *)
{ {
@ -63,48 +63,51 @@
"default": {"default": {}} "default": {"default": {}}
} }
} }
(* endvariables *) (* endvariables -*)
(* extends "layout.tex" *) (*- extends "layout.tex" -*)
(* block songbookpackages *) (* block songbookpackages *)
\usepackage[((booktype)), \usepackage[
(* for option in bookoptions *)((option)), ((booktype)),
(* endfor *) (* for option in bookoptions *)((option)),
(* for instrument in instruments *)((instrument)), (* endfor *)
(* endfor *)]{patacrep} (* for instrument in instruments *)((instrument)),
(* endfor *)
]{patacrep}
(* endblock *) (* endblock *)
(* block songbookpreambule *) (* block songbookpreambule *)
(( super() )) (( super() ))
(* for lang in _languages *) (* for lang in _languages -*)
\PassOptionsToPackage{((lang))}{babel} \PassOptionsToPackage{((lang))}{babel}
(* endfor *) (* endfor *)
\usepackage[((lang))]{babel} \usepackage[((lang))]{babel}
\lang{((lang))} \lang{((lang))}
\usepackage{graphicx} \usepackage{graphicx}
\graphicspath{(* for dir in datadir *) \graphicspath{ %
{(( path2posix(dir) ))/img/} % (* for dir in datadir *)
(* endfor *) {(( path2posix(dir) ))/img/} %
} (* endfor *)
}
\makeatletter \makeatletter
\@ifpackageloaded{hyperref}{}{ \@ifpackageloaded{hyperref}{}{
\usepackage{url} \usepackage{url}
\newcommand{\phantomsection}{} \newcommand{\phantomsection}{}
\newcommand{\hyperlink}[2]{#2} \newcommand{\hyperlink}[2]{#2}
\newcommand{\href}[2]{\expandafter\url\expandafter{#1}} \newcommand{\href}[2]{\expandafter\url\expandafter{#1}}
} }
\makeatother \makeatother
(* endblock *) (* endblock *)
(* block songs *) (* block songs *)
\phantomsection \phantomsection
\addcontentsline{toc}{section}{\songlistname} \addcontentsline{toc}{section}{\songlistname}
((render_content(content) )) ((render_content(content) ))
(* endblock *) (* endblock *)

21
patacrep/songs/chordpro/data/latex/chordpro.tex

@ -1,26 +1,27 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ((path)) % ((path))
(* if language is defined *) (* if language is defined -*)
\selectlanguage{((language))} \selectlanguage{((language))}
(* endif *) (* endif *)
\songcolumns{((metadata.columns))} \songcolumns{((metadata.columns))}
\beginsong{((titles))}[ \beginsong{((titles))}[
by={((authors))}, by={((authors))},
(* for (key, argument) in beginsong *) (* for (key, argument) in beginsong *)
((key))={((argument))}, ((key))={((argument))},
(* endfor *) (* endfor *)
] ]
(* if (metadata.cov is defined) or (metadata.vcov is defined) *) (* if (metadata.cov is defined) or (metadata.vcov is defined) *)
\cover \cover
(* endif *) (* endif -*)
(* for item in content *) (* for item in content -*)
(( render(item) )) (( render(item) ))
(* endfor *) (* endfor *)
\endsong \endsong
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

4
patacrep/songs/chordpro/data/latex/content_line.tex

@ -1 +1,3 @@
(* for item in content.line *)(( render(item) ))(* endfor *) (* for item in content.line -*)
(( render(item) ))
(*- endfor *)

3
patacrep/songs/chordpro/data/latex/content_verse.tex

@ -1,6 +1,5 @@
\begin{(( content.type ))} \begin{(( content.type ))}
(* for line in content.lines *) (* for line in content.lines -*)
(( render(line) )) (( render(line) ))
(* endfor *) (* endfor *)
\end{(( content.type ))} \end{(( content.type ))}

32
patacrep/templates.py

@ -22,22 +22,22 @@ _LATEX_SUBS = (
_VARIABLE_REGEXP = re.compile( _VARIABLE_REGEXP = re.compile(
r""" r"""
\(\*\ *variables\ *\*\) # Match (* variables *) \(\*-?\ *variables\ *\*\) # Match (* variables *) or (*- variables *)
( # Match and capture the following: ( # Match and capture the following:
(?: # Start of non-capturing group, used to match a single character (?: # Start of non-capturing group, used to match a single character
(?! # only if it's impossible to match the following: (?! # only if it's impossible to match the following:
\(\*\ * # - a literal (* \(\*-?\ * # - a literal (* or (*-
(?: # Inner non-capturing group, used for the following alternation: (?: # Inner non-capturing group, used for the following alternation:
variables # - Either match the word variables variables # - Either match the word variables
| # or | # or
endvariables # - the word endvariables endvariables # - the word endvariables
) # End of inner non-capturing group ) # End of inner non-capturing group
\ *\*\) # - a literal *) \ *-?\*\) # - a literal *) or -*)
) # End of negative lookahead assertion ) # End of negative lookahead assertion
. # Match any single character . # Match any single character
)* # Repeat as often as possible )* # Repeat as often as possible
) # End of capturing group 1 ) # End of capturing group 1
\(\*\ *endvariables\ *\*\) # until (* endvariables *) is matched. \(\*\ *endvariables\ *-?\*\) # until (* endvariables *) or (* endvariables -*) is matched.
""", """,
re.VERBOSE|re.DOTALL) re.VERBOSE|re.DOTALL)

Loading…
Cancel
Save