Commits

Brian Mearns committed 1891be8

Added new feature, line-wrap support for latex.

Comments (0)

Files changed (4)

-Rel 12 - vX.X.X.X - XXXX-XX-XX
-
+Rel 12 - v1.5.0.0 - 2013-05-15
+    [n] Added some basic linewrap to the paragraph text for latex output.
+        Access with -L option.
 
 Rel 11 - v1.4.2.0 - 2013-05-02
     [p] Fixed the samepage/verbatim for writeLatex. (cs 4d688346b881)
         default=None
     )
     argp.add_argument('-L', '--line-width',
-        help="For txt output format, specifies the width of the line.",
+        help="For txt, flow, and latex output format, specifies the width of the line. Default for txt and flow is 78, default for latex is no linewrap.",
         dest='line_width',
-        default=78,
+        default=None,
         type=int
     )
     argp.add_argument('-t', '--template-file',
             doc.writexml(outStream, indent="", addindent=addindent, newl=newl, encoding="UTF-8")
 
         elif args.format == "txt":
-            writer = writeText.TextWriter(args.line_width)
+            lw = args.line_width
+            if lw is None:
+                lw = 78
+            writer = writeText.TextWriter(lw)
             writer.writeText(tome, outStream)
 
         elif args.format == "flow":
-            writer = writeFlow.FlowWriter(outStream, args.line_width)
+            lw = args.line_width
+            if lw is None:
+                lw = 78
+            writer = writeFlow.FlowWriter(outStream, lw)
             writer.writeFlow(tome)
 
         elif args.format == "latex":
-            writeLatex.writeLatex(tome, outStream, templateFile=args.template_file, draft=args.draft)
+            writeLatex.writeLatex(tome, outStream, templateFile=args.template_file, draft=args.draft, linewrap=args.line_width)
 
         elif args.format == "epub":
 

src/tome/version.py

 # Dev and blood versions are still numbered for the *previous* version,
 # because we may not know what the next version will be until we're finished.
 
-RELEASE     = 11
+RELEASE     = 12
 
 MAJOR       = 1
-MINOR       = 4
-PATCH       = 2
+MINOR       = 5
+PATCH       = 0
 SEMANTIC    = 0
 
 YEAR        = 2013
 MONTH       = 5
-DAY         = 2
+DAY         = 15
 COPYRIGHT   = YEAR
 
-TAG         = "dev"
-#TAG         = None
+#TAG         = "dev"
+TAG         = None
 
 
 

src/tome/writeLatex.py

 import templ.tstreams
 import cStringIO
 import pkg_resources
+import wrapUtil
 
 def latexEscape(text):
     return text.replace("\\", "\\\\").replace("_", "\\_").replace("{", "\\{").replace("}", "\\}")
         raise TypeError("Unexpected type for segment.")
 
         
-def writeLatex(tome, ostream, templateFile=None, draft=False):
+def writeLatex(tome, ostream, templateFile=None, draft=False, linewrap=None):
     #TODO: Add parts and books
 
     if templateFile is None:
                         if parPreformatted:
                             buf.write("\\begin{samepage}\n\\begin{verbatim}\n")
 
+                        parBuf = cStringIO.StringIO()
                         for k in xrange(len(paragraph)):
-                            writeSegment(buf, paragraph[k], i==0 and j==0 and k==0 and (not parPreformatted), verbatim=parPreformatted)
+                            writeSegment(parBuf, paragraph[k], i==0 and j==0 and k==0 and (not parPreformatted), verbatim=parPreformatted)
+
+                        par = parBuf.getvalue()
+                        parBuf.close()
+                        if linewrap is not None and not parPreformatted:
+                            lines = wrapUtil.wrapText(par, linewrap)
+                            buf.write("\n".join((" ".join(line)) for line in lines))
+                        else:
+                            buf.write(par)
 
                         if parPreformatted:
                             buf.write("\\end{verbatim}\n\\end{samepage}\n")