Commits

Robert Mařík committed d1a558e

Wrapping lines preserves old linebraks. Customization in .sws2tex possible.

  • Participants
  • Parent commits d3f56c9

Comments (0)

Files changed (2)

File .sws2tex_example

 """
 lang = "czech"
 author = "Your Name"
+word_wrap = 1
 def line_breaks(text, columns=85, options=None):
     r"""
     Split the string into lines of length columns.
-
     
     - options.word_wrap = 0 : no wrapping
-    - options.word_wrap = 1 : wrapping using textwrap mpdule
+    - options.word_wrap = 1 : wrapping using textwrap module
     - options.word_wrap = 2 : fixed line length
     
 
     """
-    if options.word_wrap == 0:
-        return text
-    if options.word_wrap == 1:
-        return "\n".join(textwrap.wrap(text,columns))+"\n"
     newlines = ""
     for line in text.splitlines():
-        while len(line) >= columns:
-            newlines += line[0:columns] + '\\\n'
-            #if line[0:columns].find(' ') == -1:
-            #    newlines += '\n'
-            line = line[columns:]
-        newlines += line + '\n'
+        if options.word_wrap == 0:
+            newlines += line + '\n'
+        elif options.word_wrap == 1:
+            newlines += textwrap.fill(line,columns) + "\n"
+        else:
+            while len(line) >= columns:
+                newlines += line[0:columns] + '\\\n'
+                #if line[0:columns].find(' ') == -1:
+                #    newlines += '\n'
+                line = line[columns:]
+            newlines += line + '\n'
     return newlines
 
 
 usage = r"""
 usage: %prog [options] input [output]
 
-You may want to specify LaTeX preamble, author and language via configuration
-in .sws2tex config file in current directory or in your home directory
-(see .sws2tex_example). Command line options override this settings.
+You may want to set your defaulot LaTeX preamble, author, language and
+word_wrap in .sws2tex config file in current directory or in your home
+directory (see .sws2tex_example). Command line options override this
+settings.
 """
 opt_parser = OptionParser(usage = usage)
 opt_parser.add_option("-q", "--quiet",
                       help = "do not print cell with %hide token")
 
 opt_parser.add_option("-W", "--word_wrap",
-                      action = "store", type = 'int', dest = "word_wrap", default = 1,
+                      action = "store", type = 'int', dest = "word_wrap", default = None,
                       help = "select method for word wrap: 0 (no wrapping), 1 (textwraper, default), 2 (fixed line length)")
 
 (options, args) = opt_parser.parse_args()
         filename = '.sws2tex'
     elif os.path.exists(os.path.expanduser("~/.sws2tex")):
         filename = os.path.expanduser("~/.sws2tex")
+    if not options.quiet:
+        print "Config file: %s" %filename
     config = ConfigObj(filename)
 except:
     config = {}
     if config.has_key('author'):
         options.author = config['author']
 
+if options.word_wrap is None:
+    if config.has_key('word_wrap'):
+        options.word_wrap = int(config['word_wrap'])
+    else:
+        options.word_wrap = 1
+
 if options.lang is not None:
     preamble += "\usepackage[%s]{babel}" % options.lang
 elif config.has_key('lang'):