papyrus 0.0.1 → 0.0.2.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ = History of Papyrus
2
+
3
+ This file describes the most important changes made to Papyrus between
4
+ two releases. For a comprehensive list, see the
5
+ {source archive}[http://devel.pegasus-alpha.eu/projects/papyrus/repository].
6
+
7
+ Bug fixes are written in <i>italic</i>, important changes in
8
+ <b>bold</b>.
9
+
10
+ == 0.0.2
11
+
12
+ * Much more stable now!
13
+ * <b>Added commandline option <tt>--append-source</tt></b>
14
+ * <b>Added commandline option <tt>--inputencoding</tt></b>
15
+ * <i>Fixed an encoding problem on Windows</i>
16
+ * <b>Switched to XeTeX as the underlying engine instead of
17
+ pdfLaTeX</b>
18
+ * Fixed handling of verbatim text inside headings and description
19
+ lists
@@ -14,7 +14,27 @@ cross-reference facilities).
14
14
  Version 1.9.2 or greater required.
15
15
  * RDoc[http://github.com/rdoc/rdoc], the Ruby documentation tool, version 3.9 or greater.
16
16
  * The generator uses LaTeX[http://latex-project.org] to generate the PDF files
17
- (pdfLaTeX, to be exact), so you’ll need this as well. LaTeX2e required.
17
+ (XeLaTeX, to be exact), so you’ll need this as well. LaTeX2e required.
18
+ * In addition to LaTeX itself, the following LaTeX packages need to be
19
+ installed:
20
+ * fontspec
21
+ * xunicode
22
+ * textcomp
23
+ * eurosym
24
+ * lastpage
25
+ * geometry
26
+ * fancyhdr
27
+ * fancyvrb
28
+ * longtable
29
+ * xcolor
30
+ * titlesec
31
+ * titletoc
32
+ * hyperref
33
+ If any of these is missing, you'll get that obscure
34
+ Invoking xelatex failed with exitstatus 1!
35
+ message. To see which was the cause for this error, you can
36
+ pass the <tt>--debug</tt> option to RDoc as in:
37
+ rdoc -f papyrus --debug WHATEVERYOUWANTTODOCUMENT
18
38
 
19
39
  == Installation
20
40
 
@@ -27,6 +47,7 @@ If you prefer to be on the bleeding edge, clone the sourcecode
27
47
  repository and build the gem yourself:
28
48
 
29
49
  $ git clone http://git.pegasus-alpha.eu/papyrus.git
50
+ $ git checkout devel
30
51
  $ rake gem
31
52
  # gem install --local --pre pkg/papyrus-x.y.z
32
53
 
@@ -68,8 +89,8 @@ The PDF generator adds some commandline options to RDoc, namely:
68
89
  you may turn them off via <tt>--no-show-pages</tt>. Defaults
69
90
  to true.
70
91
  [<tt>--latex-command</tt>]
71
- If your pdfLaTeX’s executable for whatever reason isn’t named
72
- +pdflatex+ (the default), you can set the name here.
92
+ If your XeLaTeX’s executable for whatever reason isn’t named
93
+ +xelatex+ (the default), you can set the name here.
73
94
  [<tt>--babel-lang</tt>]
74
95
  If you write your documentation in a language other than English,
75
96
  this option may be interesting for you. It specified the option(s)
@@ -80,8 +101,10 @@ The PDF generator adds some commandline options to RDoc, namely:
80
101
 
81
102
  == Web pages
82
103
 
83
- * The project is hosted here: http://redmine.pegasus-alpha.eu/projects/papyrus
84
- * Report bugs at: http://redmine.pegasus-alpha.eu/projects/papyrus/issues
104
+ * The project is hosted here: http://devel.pegasus-alpha.eu/projects/papyrus
105
+ * Report bugs at: http://devel.pegasus-alpha.eu/projects/papyrus/issues
106
+ * The Git repository can be seen here: http://devel.pegasus-alpha.eu/projects/papyrus/repository
107
+ * The Git repository is mirrored to GitHub: https://github.com/Quintus/Papyrus
85
108
 
86
109
  == Known Problems
87
110
 
@@ -89,6 +112,27 @@ The PDF generator adds some commandline options to RDoc, namely:
89
112
  This is a technical restriction as the complex references this
90
113
  template creates confuse LaTeX when used in that places.
91
114
 
115
+ == When it crashes
116
+
117
+ Before you report a bug against Papyrus (see above) you should
118
+ check wheather it's really Papyrus' fault or your setup's.
119
+ Installing LaTeX can be a tricky task, so make sure everything
120
+ is where it ought to be. You should also try to run rdoc with the
121
+ <tt>--debug</tt> option which will turn on RDoc's and Papyrus'
122
+ debug mode. Using this can cause masses of output, so be prepared.
123
+ Usually you'll find something like
124
+
125
+ ! LaTeX error: ...
126
+
127
+ somewhere in the output--this will tell you what went wrong.
128
+
129
+ If you're sure you've found some misbehaviour in Papyrus (which
130
+ is totally legit as we're all human beings that tend to make
131
+ mistakes) use the bugtracker pointed to above and include the
132
+ output of a debug run along with your Ruby and RDoc version.
133
+ Please also attach a description on what you did and (if useful)
134
+ what you expected Papyrus to do.
135
+
92
136
  == Author
93
137
 
94
138
  This software was written by Marvin Gülker for the German company
@@ -129,4 +173,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
129
173
  As soon as Ruby 1.9.3 final is out, this will be licensed under GPLv3.
130
174
  Just in case you wonder why it isn’t that yet, Ruby’s license is at the
131
175
  moment not compatible with the GPLv3, but with the upcomming 1.9.3 release,
132
- Ruby switches to a BSD-style license which allows this.
176
+ Ruby switches to a BSD-style license which allows this.
177
+
178
+ === Font license
179
+
180
+ The fonts included by Papyrus are copyrighted by Philipp H. Poll
181
+ (http://linuxlibertine.sf.net) and licensed under the Open Font
182
+ license. See the OFL.txt file in the data/fonts directory for more
183
+ information.
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2-beta1
@@ -0,0 +1,98 @@
1
+ This Font Software is Copyright (c) 2003-2006, Philipp H. Poll (http://linuxlibertine.sf.net/).
2
+ All Rights Reserved.
3
+
4
+ "Linux Libertine" is a Reserved Font Name for this Font Software.
5
+
6
+ This Font Software is licensed under the SIL Open Font License, Version 1.0.
7
+ No modification of the license is permitted, only verbatim copy is allowed.
8
+ This license is copied below, and is also available with a FAQ at:
9
+ http://scripts.sil.org/OFL
10
+
11
+
12
+ -----------------------------------------------------------
13
+ SIL OPEN FONT LICENSE Version 1.0 - 22 November 2005
14
+ -----------------------------------------------------------
15
+
16
+ PREAMBLE
17
+ The goals of the Open Font License (OFL) are to stimulate worldwide
18
+ development of cooperative font projects, to support the font creation
19
+ efforts of academic and linguistic communities, and to provide an open
20
+ framework in which fonts may be shared and improved in partnership with
21
+ others.
22
+
23
+ The OFL allows the licensed fonts to be used, studied, modified and
24
+ redistributed freely as long as they are not sold by themselves. The
25
+ fonts, including any derivative works, can be bundled, embedded,
26
+ redistributed and sold with any software provided that the font
27
+ names of derivative works are changed. The fonts and derivatives,
28
+ however, cannot be released under any other type of license.
29
+
30
+ DEFINITIONS
31
+ "Font Software" refers to any and all of the following:
32
+ - font files
33
+ - data files
34
+ - source code
35
+ - build scripts
36
+ - documentation
37
+
38
+ "Reserved Font Name" refers to the Font Software name as seen by
39
+ users and any other names as specified after the copyright statement.
40
+
41
+ "Standard Version" refers to the collection of Font Software
42
+ components as distributed by the Copyright Holder.
43
+
44
+ "Modified Version" refers to any derivative font software made by
45
+ adding to, deleting, or substituting -- in part or in whole --
46
+ any of the components of the Standard Version, by changing formats
47
+ or by porting the Font Software to a new environment.
48
+
49
+ "Author" refers to any designer, engineer, programmer, technical
50
+ writer or other person who contributed to the Font Software.
51
+
52
+ PERMISSION & CONDITIONS
53
+ Permission is hereby granted, free of charge, to any person obtaining
54
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
55
+ redistribute, and sell modified and unmodified copies of the Font
56
+ Software, subject to the following conditions:
57
+
58
+ 1) Neither the Font Software nor any of its individual components,
59
+ in Standard or Modified Versions, may be sold by itself.
60
+
61
+ 2) Standard or Modified Versions of the Font Software may be bundled,
62
+ redistributed and sold with any software, provided that each copy
63
+ contains the above copyright notice and this license. These can be
64
+ included either as stand-alone text files, human-readable headers or
65
+ in the appropriate machine-readable metadata fields within text or
66
+ binary files as long as those fields can be easily viewed by the user.
67
+
68
+ 3) No Modified Version of the Font Software may use the Reserved Font
69
+ Name(s), in part or in whole, unless explicit written permission is
70
+ granted by the Copyright Holder. This restriction applies to all
71
+ references stored in the Font Software, such as the font menu name and
72
+ other font description fields, which are used to differentiate the
73
+ font from others.
74
+
75
+ 4) The name(s) of the Copyright Holder or the Author(s) of the Font
76
+ Software shall not be used to promote, endorse or advertise any
77
+ Modified Version, except to acknowledge the contribution(s) of the
78
+ Copyright Holder and the Author(s) or with their explicit written
79
+ permission.
80
+
81
+ 5) The Font Software, modified or unmodified, in part or in whole,
82
+ must be distributed using this license, and may not be distributed
83
+ under any other license.
84
+
85
+ TERMINATION
86
+ This license becomes null and void if any of the above conditions are
87
+ not met.
88
+
89
+ DISCLAIMER
90
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
91
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
92
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
93
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
94
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
95
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
96
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
97
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
98
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -34,9 +34,8 @@
34
34
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
35
 
36
36
  \usepackage[<%= babel_lang %>]{babel} %Hyphenation, etc.
37
- \usepackage[utf8]{inputenc} %Input encoding: UTF-8
38
- \usepackage[T1]{fontenc} %Output encoding: T1
39
- \usepackage{lmodern} %Pretty fonts for T1
37
+ \usepackage{fontspec} %XeTeX font selsection made easy
38
+ \usepackage{xunicode} %Correct unicode characters (for searching, etc.)
40
39
  \usepackage{textcomp} %Useful things like \textdegree
41
40
  \usepackage[official]{eurosym} %Official \euro symbol
42
41
  \usepackage{lastpage} %Get a reference on the last page
@@ -46,13 +45,12 @@
46
45
  \usepackage{longtable}
47
46
  %\usepackage{amsmath} %For math
48
47
  %\usepackage{amsfonts} %Math fonts
49
- %\usepackage[retainorgcmds]{IEEEtrantools} %For equations
50
- %\usepackage{listings} %Syntax hightlighting
48
+ \usepackage{listings} %Syntax hightlighting
51
49
  \usepackage{xcolor} %Colored text
52
50
  %\usepackage{graphicx} %Graphics
53
51
  \usepackage{titlesec} %Easily define new heading styles
54
52
  \usepackage{titletoc} %For telling LaTeX where to put the new headings in the TOC
55
- \usepackage[unicode=true,pdftex]{hyperref} %For hyperlinks
53
+ \usepackage[xetex]{hyperref} %For hyperlinks
56
54
 
57
55
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58
56
  % General information
@@ -139,6 +137,30 @@
139
137
  \setlength{\headheight}{14.5pt} %Otherwise LaTeX complains
140
138
  \renewcommand{\headrulewidth}{0.4pt}
141
139
 
140
+ % fontspec
141
+ \setmainfont[Path = <%= FONT_DIR %>/,
142
+ UprightFont = *_R,
143
+ BoldFont = *_RB,
144
+ ItalicFont = *_RI,
145
+ %SmallCapsFont = *_aS, %This gives "Metric (TFM) file or installed font not found."
146
+ BoldItalicFont = *_RBI]{LinLibertine}
147
+
148
+ \setsansfont[Path = <%= FONT_DIR %>/,
149
+ UprightFont = *_R,
150
+ BoldFont = *_RB,
151
+ ItalicFont = *_RI,
152
+ SmallCapsFont = *_aS,
153
+ BoldItalicFont = *_aBL]{LinBiolinum} % Yes, I know, but there is no
154
+ % _RBI for Biolinum
155
+
156
+ % lstlistings
157
+ \lstset{
158
+ basicstyle=\ttfamily\small, %Monospaced sourecode, small
159
+ showstringspaces=false, %Suppress marking spaces in strings
160
+ keywordstyle=\color{olive}, %Green keywords
161
+ commentstyle=\itshape\color{gray} %Grey and italic comments
162
+ }
163
+
142
164
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143
165
  % Document start
144
166
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -179,8 +201,33 @@
179
201
  \clearpage
180
202
 
181
203
  \section{Class and module reference}
182
- <% @classes_and_modules.each do |mod| %>
204
+ %<% @classes_and_modules.each do |mod| %>
183
205
  \input{<%= render_module(mod) %>}\clearpage %Always start a new page for a new class/module
184
- <% end %>
206
+ %<% end %>
207
+
208
+ %<% if @options.append_source %>
209
+ \appendix
210
+ \section{Sourcecode}
211
+
212
+ Following is the sourcode of all the methods that have been
213
+ documented, sorted as follows:
214
+
215
+ \begin{enumerate}
216
+ \item Classes and modules are sorted alphabetically.
217
+ \item Class/module methods go before instance methods.
218
+ \item The methods are sorted alphabetically.
219
+ \end{enumerate}
220
+
221
+ % <% @classes_and_modules.each do |mod| %>
222
+ \subsection{<%= mod.latexized(:full_name) %>}
223
+
224
+ % <% mod.method_list.sort.each do |meth| %>
225
+ \method{<%= meth.latexized(:pretty_name) %>}
226
+ \begin{lstlisting}[language=<%= meth.c_function ? "c" : "ruby" %>]
227
+ <%= meth.tokens_to_s rescue "NOT FOUND" %>
228
+ \end{lstlisting}
229
+ % <% end %>
230
+ % <% end %>
231
+ %<% end %>
185
232
 
186
233
  \end{document}
@@ -53,7 +53,7 @@
53
53
  % <% consts.each do |const| %>
54
54
  \label{<%= const.latex_label %>}%
55
55
  \small{\code{<%= const.latexized :name %>}} & %
56
- \small{\code{<%= const.latexized_value %>}} & %
56
+ \small{\code{<%= const.latexized_value.delete("\n") %>}} & %
57
57
  <%= const.description %> \\
58
58
  & & \\ %Empty row for readability
59
59
  % <% end %>
@@ -28,6 +28,22 @@
28
28
  #would therefore take precedence during method lookup.
29
29
  module RDoc::Generator::LaTeX_Markup
30
30
 
31
+ #Special escapes to be used inside the hyperref labels
32
+ #(hyperref doesn't accept the normal escapes correctly
33
+ #or not at all (in case of _ -> \_). A hash of form:
34
+ # "char" => "escape"
35
+ LABEL_ESCAPE = {
36
+ "#" => ":INST:",
37
+ "%" => ":perc:",
38
+ "^" => ":xor:",
39
+ "&" => ":amp:",
40
+ "_" => ":und:",
41
+ "~" => ":tilde:",
42
+ "[" => ":rbracket:",
43
+ "]" => ":lbracket:",
44
+ "=" => ":equal:"
45
+ }.freeze
46
+
31
47
  #Create an unique label for this CodeObject.
32
48
  #==Return value
33
49
  #A string (hopefully) uniquely identifying this CodeObject. Intended for
@@ -36,9 +52,9 @@ module RDoc::Generator::LaTeX_Markup
36
52
  #[PapyrusError] +self+ isn’t a CodeObject (→ Context::Section).
37
53
  def latex_label
38
54
  case self
39
- when RDoc::Context then "class-module-#{full_name}"
40
- when RDoc::MethodAttr then "method-attr-#{full_name.gsub('#', '+')}" # '#' doesn’t work in references
41
- when RDoc::Constant then "const-#{parent.full_name}::#{name}"
55
+ when RDoc::Context then "class-module-#{label_escape(full_name)}"
56
+ when RDoc::MethodAttr then "method-attr-#{label_escape(full_name)}"
57
+ when RDoc::Constant then "const-#{label_escape(parent.full_name)}::#{label_escape(name)}"
42
58
  else
43
59
  raise(RDoc::Generator::Papyrus::PapyrusError, "Unrecognized token: #{self.inspect}!")
44
60
  end
@@ -73,6 +89,7 @@ module RDoc::Generator::LaTeX_Markup
73
89
 
74
90
  @formatter = RDoc::Markup::ToLaTeX_Crossref.new(self.kind_of?(RDoc::Context) ? self : @parent, #Thanks to RDoc for this
75
91
  current_heading_level,
92
+ RDoc::RDoc.current.options.inputencoding,
76
93
  RDoc::RDoc.current.options.show_hash,
77
94
  RDoc::RDoc.current.options.show_pages,
78
95
  RDoc::RDoc.current.options.hyperlink_all)
@@ -93,6 +110,19 @@ module RDoc::Generator::LaTeX_Markup
93
110
  0
94
111
  end
95
112
  end
113
+
114
+ private
115
+
116
+ #Uses the LABEL_ESCAPE hash to replace all necessary characters
117
+ #in +str+ and returns the result.
118
+ def label_escape(str)
119
+ res = str.dup
120
+ LABEL_ESCAPE.each_pair do |char, esc|
121
+ res.gsub!(char, esc)
122
+ end
123
+ res
124
+ end
125
+
96
126
  end
97
127
 
98
128
  #FIXME:
@@ -72,17 +72,22 @@ class RDoc::Generator::Papyrus
72
72
  #Description displayed in RDoc’s help.
73
73
  DESCRIPTION = "PDF generator based on LaTeX"
74
74
 
75
+ #Root directory of this project.
76
+ ROOT_DIR = Pathname.new(__FILE__).dirname.parent.parent.parent
77
+
75
78
  #The version number.
76
- VERSION = Pathname.new(__FILE__).dirname.parent.parent.parent.join("VERSION.txt").read.chomp.freeze
79
+ VERSION = ROOT_DIR.join("VERSION.txt").read.chomp.freeze
77
80
 
78
81
  #Directory where the LaTeX template files are stored.
79
- TEMPLATE_DIR = Pathname.new(__FILE__).dirname.expand_path.join("..", "..", "..", "data")
82
+ DATA_DIR = ROOT_DIR + "data"
83
+ #Directory where the internal fonts are stored.
84
+ FONT_DIR = DATA_DIR + "fonts"
80
85
  #The main file’s ERB template.
81
- MAIN_TEMPLATE = ERB.new(TEMPLATE_DIR.join("main.tex.erb").read)
86
+ MAIN_TEMPLATE = ERB.new(File.open(DATA_DIR.join("main.tex.erb"), "r:UTF-8"){|f| f.read})
82
87
  #The ERB template for a single file.
83
- RDOC_FILE_TEMPLATE = ERB.new(TEMPLATE_DIR.join("rdoc_file.tex.erb").read)
88
+ RDOC_FILE_TEMPLATE = ERB.new(File.open(DATA_DIR.join("rdoc_file.tex.erb"), "r:UTF-8"){|f| f.read})
84
89
  #The ERB template for a single class or module.
85
- MODULE_TEMPLATE = ERB.new(TEMPLATE_DIR.join("module.tex.erb").read)
90
+ MODULE_TEMPLATE = ERB.new(File.open(DATA_DIR.join("module.tex.erb"), "r:UTF-8"){|f| f.read})
86
91
 
87
92
  #Basename of the main resulting LaTeX file. The path is prepended
88
93
  #later as it’s a temporary directory.
@@ -91,32 +96,6 @@ class RDoc::Generator::Papyrus
91
96
  #temporary directory.
92
97
  MAIN_FILE_RESULT_BASENAME = "main.pdf"
93
98
 
94
- #Creates a new instance of this class. Automatically called by RDoc.
95
- #There shouldn’t be any need for you to call this.
96
- #==Parameter
97
- #[options] RDoc passes the current RDoc::Options instance here.
98
- #==Return value
99
- #The newly created instance.
100
- def initialize(options)
101
- #The requiring of the rest of the library *must* be placed here,
102
- #because otherwise it’s loaded during RDoc’s discovering process,
103
- #effectively eliminating the possibility to generate anything
104
- #other than LaTeX output due to the overwrites the
105
- #RDoc::Generator::LaTeX_Markup module does.
106
- require_relative "../markup/to_latex_crossref"
107
- require_relative "latex_markup"
108
-
109
- @options = options
110
- @output_dir = Pathname.pwd.expand_path + @options.op_dir
111
- #The following variable is used to generate unique filenames.
112
- #During processing the ERB templates, many files are created and
113
- #accidentally creating two files with the same name, effectively
114
- #overwriting the previous one, should be avoided. Hence, this
115
- #little number is prepended to generated filenames (except the
116
- #main file).
117
- @counter = 0
118
- end
119
-
120
99
  class << self
121
100
 
122
101
  #Called by RDoc during option processing. Adds commandline
@@ -128,19 +107,34 @@ class RDoc::Generator::Papyrus
128
107
  #Define the methods to get and set the options
129
108
  options.extend(RDoc::Generator::Papyrus::Options)
130
109
 
110
+ options.option_parser.separator ""
111
+ options.option_parser.separator "Papyrus generator options:"
112
+ options.option_parser.separator ""
113
+
131
114
  #Define the options themselves
132
- options.option_parser.on("--[no-]show-pages", "(pdf_latex) Enables or disables page", "numbers following hyperlinks (default true).") do |val|
115
+ options.option_parser.on("--[no-]show-pages", "Enables or disables page", "numbers following hyperlinks (default true).") do |val|
133
116
  debug("Found --show-pages: #{val}")
134
117
  options.show_pages = val
135
118
  end
136
- options.option_parser.on("--latex-command=VALUE", "(pdf_latex) Sets the command to run", "LaTeX (defaults to '#{RDoc::Generator::Papyrus::Options::DEFAULT_LATEX_COMMAND}')") do |val|
119
+ options.option_parser.on("--latex-command=VALUE", " Sets the command to run", "LaTeX (defaults to '#{RDoc::Generator::Papyrus::Options::DEFAULT_LATEX_COMMAND}')") do |val|
137
120
  debug("Found --latex-command: #{val}")
138
121
  options.latex_command = val
139
122
  end
140
- options.option_parser.on("--babel-lang=VALUE", "(pdf_latex) Sets the language option", "for babel (defaults to '#{RDoc::Generator::Papyrus::Options::DEFAULT_BABEL_LANG}')") do |val|
123
+ options.option_parser.on("--babel-lang=VALUE", "Sets the language option", "for babel (defaults to '#{RDoc::Generator::Papyrus::Options::DEFAULT_BABEL_LANG}')") do |val|
141
124
  debug("Found --babel-lang: #{val}")
142
125
  options.babel_lang = val
143
126
  end
127
+
128
+ options.option_parser.on("--inputencoding", "Sets the encoding used for the input files.", "Defaults to '#{RDoc::Generator::Papyrus::Options::DEFAULT_INPUT_ENCODING}'.") do |val|
129
+ debug("Found --inputencoding: #{val}")
130
+ options.inputencoding = val
131
+ end
132
+
133
+ options.option_parser.on("--[no-]append-source",
134
+ "If set, the sourcecode of all methods is included",
135
+ "as an appendix (warning: HUGE PDF",
136
+ "files can be the result! Default: false."){|val| options.append_source = val}
137
+
144
138
  end
145
139
 
146
140
  private
@@ -158,6 +152,32 @@ class RDoc::Generator::Papyrus
158
152
 
159
153
  end
160
154
 
155
+ #Creates a new instance of this class. Automatically called by RDoc.
156
+ #There shouldn’t be any need for you to call this.
157
+ #==Parameter
158
+ #[options] RDoc passes the current RDoc::Options instance here.
159
+ #==Return value
160
+ #The newly created instance.
161
+ def initialize(options)
162
+ #The requiring of the rest of the library *must* be placed here,
163
+ #because otherwise it’s loaded during RDoc’s discovering process,
164
+ #effectively eliminating the possibility to generate anything
165
+ #other than LaTeX output due to the overwrites the
166
+ #RDoc::Generator::LaTeX_Markup module does.
167
+ require_relative "../markup/to_latex_crossref"
168
+ require_relative "latex_markup"
169
+
170
+ @options = options
171
+ @output_dir = Pathname.pwd.expand_path + @options.op_dir
172
+ #The following variable is used to generate unique filenames.
173
+ #During processing the ERB templates, many files are created and
174
+ #accidentally creating two files with the same name, effectively
175
+ #overwriting the previous one, should be avoided. Hence, this
176
+ #little number is prepended to generated filenames (except the
177
+ #main file).
178
+ @counter = 0
179
+ end
180
+
161
181
  #Called by RDoc after parsing has happened in order to generate the output.
162
182
  #This method takes the input of RDoc::TopLevel objects and tranforms
163
183
  #them by means of the RDoc::Markup::ToLaTeX_Crossref class into LaTeX
@@ -173,8 +193,10 @@ class RDoc::Generator::Papyrus
173
193
  debug("Found #{@rdoc_files.count} toplevels ending in .rdoc that will be processed")
174
194
  if @options.main_page #nil if not set, no main page
175
195
  main_index = @rdoc_files.index{|t| t.full_name == @options.main_page}
176
- @rdoc_files.unshift(@rdoc_files.slice!(main_index))
177
- debug("Main page is #{@rdoc_files.first.name}")
196
+ if main_index #nil if invalid main_page given
197
+ @rdoc_files.unshift(@rdoc_files.slice!(main_index))
198
+ debug("Main page is #{@rdoc_files.first.name}")
199
+ end
178
200
  end
179
201
 
180
202
  #Get the class, module and methods lists, sorted alphabetically by their full names
@@ -229,8 +251,10 @@ class RDoc::Generator::Papyrus
229
251
  #Remove the temporary directory (this is *not* done if invoking LaTeX
230
252
  #failed, as the #latex method throws an exception. This is useful for
231
253
  #debugging the generated LaTeX files)
232
- debug("Removing temporary directory")
233
- temp_dir.rmtree unless @options.dry_run
254
+ unless $DEBUG_RDOC
255
+ debug("Removing temporary directory")
256
+ temp_dir.rmtree unless @options.dry_run
257
+ end
234
258
  end
235
259
 
236
260
  private
@@ -321,7 +345,7 @@ class RDoc::Generator::Papyrus
321
345
  #a \hyperref to it if possible. Otherwise just returns +obj+.
322
346
  def superclass_string(obj)
323
347
  if obj.kind_of?(String)
324
- obj
348
+ RDoc::Markup::ToLaTeX.new.escape(obj) #HACK, \verb doesn't do the trick here
325
349
  else
326
350
  hyperref(obj.latex_label, obj.latexized(:full_name))
327
351
  end
@@ -333,6 +357,7 @@ class RDoc::Generator::Papyrus
333
357
  table_str = ""
334
358
  table_str << "\\small"
335
359
  table_str << "\\begin{longtable}{l|l|l|l|l|l}\n"
360
+ #table_str << "\\begin{longtable}{p{0.1666\\textwidth}|p{0.1666\\textwidth}|p{0.1666\\textwidth}|p{0.1666\\textwidth}|p{0.1666\\textwidth}|p{0.1666\\textwidth}}\n"
336
361
  table_str << " \\bfseries Name & \\bfseries p & \\bfseries Name & \\bfseries p & \\bfseries Name & \\bfseries p \\\\\n"
337
362
  table_str << " \\hline\n"
338
363
  table_str << "\\endhead\n"
@@ -35,12 +35,15 @@ module RDoc
35
35
  #The default command invoked when running LaTeX.
36
36
  #Overriden by the <tt>--latex-command</tt> commandline
37
37
  #option.
38
- DEFAULT_LATEX_COMMAND = "pdflatex"
38
+ DEFAULT_LATEX_COMMAND = "xelatex"
39
39
 
40
40
  #The default language option passed to the LaTeX +babel+
41
41
  #package.
42
42
  DEFAULT_BABEL_LANG = "english"
43
43
 
44
+ #The default encoding for the <tt>--inputencoding</tt> option.
45
+ DEFAULT_INPUT_ENCODING = "UTF-8"
46
+
44
47
  #Wheather or not to show page numbers in square
45
48
  #brackets behind any cross-reference made. Useful
46
49
  #if one is sure that the documentation won’t be printed
@@ -77,7 +80,33 @@ module RDoc
77
80
  def babel_lang=(val)
78
81
  @babel_lang = val
79
82
  end
83
+
84
+ #The encoding assumed for *all* the input files. Defautls to "UTF-8".
85
+ def inputencoding
86
+ @inputencoding ||= DEFAULT_INPUT_ENCODING
87
+ end
88
+
89
+ #Setter for the #inputencoding value.
90
+ def inputencoding=(val)
91
+ @inputencoding = val
92
+ end
93
+
94
+ #Wheather or not to include the methods' sourcecode in the
95
+ #PDF file in form of an appendix. I highly recommand you to
96
+ #not do this as the bigger a project grows, the thicker the
97
+ #resulting PDF will be. Furthermore printing the PDF would
98
+ #resulting in printing the sourcecode which is nonsense as
99
+ #you're better off directly looking into the sourcecode files
100
+ #with your favourite editor where you can edit them.
101
+ def append_source
102
+ @append_source ||= false
103
+ end
80
104
 
105
+ #Stter for the #append_source value.
106
+ def append_source=(val)
107
+ @append_source = val
108
+ end
109
+
81
110
  end
82
111
 
83
112
  end
@@ -26,7 +26,7 @@ require "rdoc/markup/inline"
26
26
 
27
27
  #This is an RDoc Converter/Formatter that turns the RDoc
28
28
  #markup into LaTeX code. It’s intended for use with
29
- #the RDoc::Generator::PDF_LaTeX class, but if you like you
29
+ #the RDoc::Generator::Papyrus class, but if you like you
30
30
  #can use it on it’s own (but note this class absolutely
31
31
  #depends on RDoc’s parser). To use it, you first have
32
32
  #to instanciate this class, and then call the #convert method
@@ -176,6 +176,15 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
176
176
  "\\subparagraph*{%s}", #Needed??
177
177
  "%s", "%s", "%s", "%s", "%s", "%s"].freeze #Everything below is just ignored.
178
178
 
179
+ #LaTeX heading commands for headings with an optional
180
+ #argument to change the TOC entry. Just reach till level 4,
181
+ #because lower headings don’t show up in the TOC at all.
182
+ LATEX_OPT_HEADINGS = [nil,
183
+ "\\section[%s]{%s}",
184
+ "\\subsection[%s]{%s}",
185
+ "\\subsubsection[%s]{%s}",
186
+ "\\subsubsubsection[%s]{%s}"
187
+ ]
179
188
  #Characters that need to be escaped for LaTeX and their
180
189
  #corresponding escape sequences. Note the order if important,
181
190
  #otherwise some things (especiallaly \ and {}) are escaped
@@ -190,7 +199,7 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
190
199
  /(?<!textbackslash){/ => "\\{",
191
200
  /(?<!textbackslash{)}/ => "\\}",
192
201
  /_/ => "\\textunderscore{}",
193
- /\.{3}/ => "\\ldots",
202
+ /\.{3}/ => "\\ldots{}",
194
203
  /~/ => "\\~",
195
204
  /©/ => "\\copyright{}",
196
205
  /LaTeX/ => "\\LaTeX{}"
@@ -222,10 +231,11 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
222
231
  #==Remarks
223
232
  #Some lines of this method have their origin in the RDoc project. See
224
233
  #the code for more details.
225
- def initialize(heading_level = 0, markup = nil)
234
+ def initialize(heading_level = 0, inputencoding = "UTF-8", markup = nil)
226
235
  super(markup)
227
236
 
228
237
  @heading_level = heading_level
238
+ @inputencoding = "UTF-8"
229
239
  @result = ""
230
240
  @list_in_progress = nil
231
241
 
@@ -235,7 +245,7 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
235
245
 
236
246
  #Add definitions for inline markup
237
247
  add_tag(:BOLD, "\\textbf{", "}")
238
- add_tag(:TT, "\\texttt{", "}")
248
+ add_tag(:TT, "\\verb~", "~")
239
249
  add_tag(:EM, "\\textit{", "}")
240
250
  end
241
251
 
@@ -255,12 +265,12 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
255
265
 
256
266
  #Adds par’s text plus newline to the result.
257
267
  def accept_paragraph(par)
258
- @result << to_latex(par.text) << "\n"
268
+ @result << to_latex(enc(par.text)) << "\n"
259
269
  end
260
270
 
261
271
  #Puts ver’s text between \begin{verbatim} and \end{verbatim}
262
272
  def accept_verbatim(ver)
263
- @result << "\\begin{Verbatim}\n" << ver.text.chomp << "\n\\end{Verbatim}\n"
273
+ @result << "\\begin{Verbatim}\n" << enc(ver.text).chomp << "\n\\end{Verbatim}\n"
264
274
  end
265
275
 
266
276
  #Adds a \rule. The rule’s height is <tt>rule.weight</tt> pt, the
@@ -284,11 +294,14 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
284
294
  #Adds \item[label_if_necessary].
285
295
  def accept_list_item_start(item)
286
296
  if item.label
297
+ #Verbatim inside list labels is dangerous!
298
+ hsh = save_verbs(enc(item.label))
299
+ @result << hsh[:save_verbs]
287
300
 
288
301
  if @list_in_progress == :NOTE
289
- @result << "\\item[#{to_latex_suppress_crossref(item.label)}:] " #Newline done by ending paragraph
302
+ @result << "\\item[#{hsh[:save_inline]}:] " #Newline done by ending paragraph
290
303
  else
291
- @result << "\\item[#{to_latex_suppress_crossref(item.label)}] " #Newline done by ending paragraph
304
+ @result << "\\item[#{hsh[:save_inline]}] " #Newline done by ending paragraph
292
305
  end
293
306
  else
294
307
  @result << "\\item " #Newline done by ending method
@@ -310,7 +323,22 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
310
323
 
311
324
  #Adds a fitting \section, \subsection, etc. for the heading.
312
325
  def accept_heading(head)
313
- @result << sprintf(LATEX_HEADINGS[@heading_level + head.level], to_latex_suppress_crossref(head.text)) << "\n"
326
+ #Verbatim text inside headings is one of LaTeX’s ways to hell.
327
+ #We need to take special care of this by means of fancyvrb’s
328
+ #\SaveVerb command plus suppressing the verbatim inside the TOC.
329
+ hsh = save_verbs(enc(head.text))
330
+
331
+ if hsh[:save_verbs].empty?
332
+ @result << sprintf(LATEX_HEADINGS[@heading_level + head.level], hsh[:save_inline]) << "\n"
333
+ else #OK, some fool must have verbatim in the heading...
334
+ @result << hsh[:save_verbs]
335
+ heading = LATEX_OPT_HEADINGS[@heading_level + head.level]
336
+ if heading
337
+ @result << sprintf(heading, hsh[:plain_inline], hsh[:save_inline]) << "\n"
338
+ else #Heading not in TOC
339
+ @result << sprintf(LATEX_HEADINGS[@heading_level + head.level], hsh[:save_inline]) << "\n"
340
+ end
341
+ end
314
342
  end
315
343
 
316
344
  #Writes the raw thing as-is into the document.
@@ -326,14 +354,18 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
326
354
  #Called for each plaintext string in a paragraph by
327
355
  #the #convert_flow method called in #to_latex.
328
356
  def convert_string(str)
329
- escape(str)
357
+ if in_tt?
358
+ enc(str)
359
+ else
360
+ escape(enc(str))
361
+ end
330
362
  end
331
363
 
332
364
  #Method copied from RDoc project and slightly modified.
333
365
  #
334
366
  #Handles hyperlinks of form {text}[url] and text[url].
335
367
  def handle_special_TIDYLINK(special)
336
- text = special.text
368
+ text = enc(special.text)
337
369
 
338
370
  return escape(text) unless text =~ /\{(.*?)\}\[(.*?)\]/ or text =~ /(\S+)\[(.*?)\]/
339
371
 
@@ -367,7 +399,7 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
367
399
  #as #to_latex, except it’ll never rely on subclasses such
368
400
  #as ToLaTeX_Crossref.
369
401
  def to_latex_suppress_crossref(item)
370
- RDoc::Markup::ToLaTeX.new(@heading_level).instance_eval do
402
+ RDoc::Markup::ToLaTeX.new(@heading_level, @inputencoding).instance_eval do
371
403
  convert_flow(@am.flow(item))
372
404
  end
373
405
  end
@@ -394,6 +426,47 @@ class RDoc::Markup::ToLaTeX < RDoc::Markup::Formatter
394
426
  "\\url{#{url}}"
395
427
  end
396
428
  end
429
+
430
+ #Finds all \verb commands in +text+ and replaces them with
431
+ #fancyvrb’s super-secure \SaveVerb-\UseVerb mechanism. Returns
432
+ #a hash of form
433
+ # {:save_verbs => str1, :save_inline => str2, :plain_inline => str3}
434
+ #where the :save_inline string contains \UseVerb commands
435
+ #making use of the \SaveVerb commands issued in the
436
+ #:save_verbs string (the latter being empty if no replacements
437
+ #were made). If replacements were made, :save_verbs ends in a
438
+ #newline character.
439
+ #
440
+ #+text+ is automatically markup up, but without cross-references,
441
+ #because where \verb is fragile, cross-references usually are as well.
442
+ #
443
+ #:plain_inline contains the marked-up string with all \verb commands
444
+ #just removed and replaced with their (LaTeX-escaped) text.
445
+ def save_verbs(text)
446
+ @save_verb_index ||= 0 #Variable just used for this method
447
+ saves = ""
448
+ inline = to_latex_suppress_crossref(text)
449
+
450
+ save_inline = inline.gsub(/\\verb~(.*?)~/) do
451
+ saves << "\\SaveVerb{verb#{@save_verb_index}}~#$1~\n"
452
+ str = "\\protect\\UseVerb{verb#{@save_verb_index}}"
453
+ @save_verb_index += 1
454
+ str #for gsub
455
+ end
456
+
457
+ {:save_verbs => saves, :save_inline => save_inline, :plain_inline => inline.gsub(/\\verb~(.*?)~/){escape($1)}}
458
+ end
459
+
460
+ #Takes +str+, makes a copy and forces the copy to the previously
461
+ #given @inputencoding. Then encodes the string into UTF-8 and returns it.
462
+ #
463
+ #This method exists, since RDoc always assumes the system encoding and
464
+ #assignes that to the strings passed to the visitor.
465
+ def enc(str)
466
+ s = str.dup
467
+ s.force_encoding(@inputencoding)
468
+ return s if @inputencoding == "UTF-8"
469
+ s.encode("UTF-8")
470
+ end
397
471
 
398
472
  end
399
-
@@ -56,8 +56,8 @@ class RDoc::Markup::ToLaTeX_Crossref < RDoc::Markup::ToLaTeX
56
56
  #The newly created instance.
57
57
  #==Example
58
58
  # f = RDoc::Markup::ToLaTeX_Crossref.new(a_rdoc_toplevel, false)
59
- def initialize(context, heading_level = 0, show_hash = false, show_pages = true, hyperlink_all = false, markup = nil)
60
- super(heading_level, markup)
59
+ def initialize(context, heading_level = 0, inputencoding = "UTF-8", show_hash = false, show_pages = true, hyperlink_all = false, markup = nil)
60
+ super(heading_level, inputencoding, markup)
61
61
 
62
62
  @context = context
63
63
  @show_hash = show_hash
@@ -107,16 +107,16 @@ class RDoc::Markup::ToLaTeX_Crossref < RDoc::Markup::ToLaTeX
107
107
  #we won’t resolve all-lowercase words (which may be false
108
108
  #positives not meant to be a reference).
109
109
  if !@hyperlink_all and special.text =~ /^[a-z]+$/
110
- return escape(special.text)
110
+ return escape(enc(special.text))
111
111
  end
112
112
 
113
- make_crossref(special.text)
113
+ make_crossref(enc(special.text))
114
114
  end
115
115
 
116
116
  #Adds handling of encountered <tt>rdoc-ref</tt> links
117
117
  #to the HYPERLINK handler of the ToLaTeX formatter.
118
118
  def handle_special_HYPERLINK(special)
119
- return make_crossref($') if special.text =~ /^rdoc-ref:/
119
+ return make_crossref($') if enc(special.text) =~ /^rdoc-ref:/
120
120
  super
121
121
  end
122
122
 
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: papyrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2.beta1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marvin Gülker
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-17 00:00:00.000000000Z
12
+ date: 2011-10-06 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rdoc
16
- requirement: &15986840 !ruby/object:Gem::Requirement
16
+ requirement: &28407160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 3.9.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *15986840
24
+ version_requirements: *28407160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hanna-nouveau
27
- requirement: &15986360 !ruby/object:Gem::Requirement
27
+ requirement: &28406740 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *15986360
35
+ version_requirements: *28406740
36
36
  description: ! 'Papyrus is a PDF generator plugin for RDoc based on LaTeX. It
37
37
 
38
38
  allows you to turn your project''s documentation into a nice PDF file
@@ -47,15 +47,27 @@ extra_rdoc_files:
47
47
  - README.rdoc
48
48
  - COPYING
49
49
  files:
50
- - data/module.tex.erb
51
50
  - data/main.tex.erb
52
51
  - data/rdoc_file.tex.erb
53
- - lib/rdoc/markup/to_latex.rb
52
+ - data/fonts/LinBiolinum_RB.otf
53
+ - data/fonts/LinBiolinum_RI.otf
54
+ - data/fonts/LinLibertine_RB.otf
55
+ - data/fonts/LinBiolinum_R.otf
56
+ - data/fonts/LinLibertine_RBI.otf
57
+ - data/fonts/OFL.txt
58
+ - data/fonts/LinLibertine_R.otf
59
+ - data/fonts/LinBiolinum_aS.otf
60
+ - data/fonts/LinLibertine_RI.otf
61
+ - data/fonts/LinBiolinum_aBL.otf
62
+ - data/fonts/LinLibertine_aS.otf
63
+ - data/module.tex.erb
54
64
  - lib/rdoc/markup/to_latex_crossref.rb
55
- - lib/rdoc/discover.rb
56
- - lib/rdoc/generator/papyrus/options.rb
65
+ - lib/rdoc/markup/to_latex.rb
57
66
  - lib/rdoc/generator/latex_markup.rb
58
67
  - lib/rdoc/generator/papyrus.rb
68
+ - lib/rdoc/generator/papyrus/options.rb
69
+ - lib/rdoc/discover.rb
70
+ - HISTORY.rdoc
59
71
  - README.rdoc
60
72
  - VERSION.txt
61
73
  - COPYING
@@ -78,13 +90,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
90
  required_rubygems_version: !ruby/object:Gem::Requirement
79
91
  none: false
80
92
  requirements:
81
- - - ! '>='
93
+ - - ! '>'
82
94
  - !ruby/object:Gem::Version
83
- version: '0'
95
+ version: 1.3.1
84
96
  requirements:
85
97
  - ! '(pdf)LaTeX2e: For the actual PDF generation.'
86
98
  rubyforge_project:
87
- rubygems_version: 1.8.8
99
+ rubygems_version: 1.8.10
88
100
  signing_key:
89
101
  specification_version: 3
90
102
  summary: PDF generator plugin for RDoc, based on LaTeX