--- txt2tags.orig 2009-09-16 08:25:15.005354000 +0200 +++ txt2tags 2009-10-06 17:19:21.051585000 +0200 @@ -1,8 +1,10 @@ #!/usr/bin/env python -# txt2tags - generic text conversion tool +# t2t - patched txt2tags generic text conversion tool # http://txt2tags.sf.net +# http://pst.libre.lu/toolz/t2t # # Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Aurelio Jargas +# Copyright 2005, 2006 Pascal Steichen # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -139,12 +141,15 @@ # first file and gui for the second. There is no --no-. # --version and --help inside %!options are also odd # -TARGETS = 'html xhtml sgml tex lout man mgp wiki gwiki doku moin pm6 txt'.split() +# pst: added ltb to TARGETS and TARGET_NAMES +# ltb which stands for latex-beamer ;) +TARGETS = 'html xhtml sgml tex ltb lout man mgp wiki gwiki doku moin pm6 txt'.split() +#pst: added handout flag FLAGS = {'headers' :1 , 'enum-title' :0 , 'mask-email' :0 , 'toc-only' :0 , 'toc' :0 , 'rc' :1 , 'css-sugar' :0 , 'css-suggar' :0 , 'css-inside' :0 , - 'quiet' :0 } + 'quiet' :0 , 'handout' :0 } OPTIONS = {'target' :'', 'toc-level' :3 , 'style' :'', 'infile' :'', 'outfile' :'', 'encoding' :'', 'config-file':'', 'split' :0 , 'lang' :'', @@ -166,6 +171,7 @@ 'xhtml': _('XHTML page'), 'sgml' : _('SGML document'), 'tex' : _('LaTeX document'), + 'ltb' : _('LaTeX-Beamer document'), 'lout' : _('Lout document'), 'man' : _('UNIX Manual page'), 'mgp' : _('MagicPoint presentation'), @@ -235,6 +241,7 @@ _(" -V, --version print program version and exit"), _(" --dump-config print all the config found and exit"), _(" --dump-source print the document source, with includes expanded"), +_(" --handout (only ltb format) create handouts of slideshowi (default OFF)"), '', _("Turn OFF options:"), " --no-outfile, --no-infile, --no-style, --no-encoding, --no-headers", @@ -456,6 +463,7 @@ 'tex': \ r"""\documentclass{article} \usepackage{graphicx} +\usepackage{beamerarticle} \usepackage[normalem]{ulem} %% needed by strike \usepackage[urlcolor=blue,colorlinks=true]{hyperref} \usepackage[%(ENCODING)s]{inputenc} %% char encoding @@ -469,6 +477,20 @@ \clearpage """, + 'ltb': \ +r"""\documentclass{beamer} +\usepackage{amsfonts,graphicx} +\usepackage[%(ENCODING)s]{inputenc} %% char encoding +\frenchspacing %% no additional spaces after periods +\usetheme{%(STYLE)s} %% user defined style + +\title{%(HEADER1)s} +\author{%(HEADER2)s} +\date{%(HEADER3)s} +\begin{document} +\frame{\titlepage} +""", + 'lout': """\ @SysInclude { doc } @Document @@ -759,6 +781,26 @@ 'pageBreak' : '\\clearpage', 'EOD' : '\\end{document}' }, + + # pst: ltb inherits all not found below from tex ;) + 'ltb': { + 'title1Open' : '\n\\section*{\a}\n\\begin{frame}\n\\frametitle{\a}', + 'title1Close' : '\\end{frame}', + 'title2Open' : '\n\\subsection*{\a}\n\\begin{frame}\n\\frametitle{\\strut}\n\\framesubtitle{\a}', + 'title2Close' : '\\end{frame}', + 'numtitle1Open' : '\n\\section{\a}\n\\begin{frame}\n\\frametitle{\a}', + 'numtitle1Close' : '\\end{frame}', + 'numtitle2Open' : '\n\\subsection{\a}\n\\begin{frame}\n\\frametitle{\\strut}\n\\framesubtitle{\a}', + 'numtitle2Close' : '\\end{frame}', + 'listOpen' : '\\begin{itemize}[<+->]', + 'numlistOpen' : '\\begin{enumerate}[<+->]', + 'deflistOpen' : '\\begin{description}[<+->]', + # verbatim and quotations aren't handled very well + # so using blockquote instead + 'blockVerbOpen' : '\\begin{quotation}[<+->]\n\\texttt{', + 'blockVerbClose' : '}\n\\end{quotation}', + 'TOC' : '\\frame{\\tableofcontents}' + }, 'lout': { 'paragraphOpen' : '@LP' , @@ -1133,6 +1175,12 @@ if HTML_LOWER: alltags['html'] = xhtml.copy() xhtml.update(alltags['xhtml']) alltags['xhtml'] = xhtml.copy() + + # pst: do the tex -> ltb inheritance + ltb = alltags['tex'].copy() + ltb.update(alltags['ltb']) + alltags['ltb'] = ltb.copy() + # Compose the target tags dictionary tags = {} @@ -1185,6 +1233,9 @@ 'autotocwithbars', # automatic TOC surrounded by bars 'mapbar2pagebreak', # map the strong bar to a page break 'titleblocks', # titles must be on open/close section blocks + # pst: new rules needed for the ltb target + 'titleblocksnodepth', # title section blocks do not use depth feature + # Target code beautify (ON/OFF) 'indentverbblock', # add leading spaces to verb block lines @@ -1291,6 +1342,13 @@ 'mapbar2pagebreak':1, 'tablecellaligntype':'column', }, + # pst: ltb inherits all except the following from tex ;) + 'ltb': { + 'titleblocks':1, + 'titleblocksnodepth':1, + 'listmaxdepth':3, + 'verbblocknotescaped':0 + }, 'lout': { 'keepquoteindent':1, 'keeplistindent':1, @@ -1391,6 +1449,9 @@ if config['target'] == 'xhtml': myrules = rules_bank['html'].copy() # inheritance myrules.update(rules_bank['xhtml']) # get XHTML specific + elif config['target'] == 'ltb': + myrules = rules_bank['tex'].copy() # inheritance + myrules.update(rules_bank['ltb']) # get ltb specific else: myrules = rules_bank[config['target']].copy() @@ -2495,6 +2556,7 @@ tag = '' last = self.last_level curr = self.level + if rules['titleblocksnodepth']: curr = last # for LTB # Same level, just close the previous if curr == last: @@ -2554,6 +2616,17 @@ if tag: ret.append(tag) self.level = self.level - 1 return ret + + # pst: new func for ltb level specifics + def close_last(self): + "Closes last opened title (ltb specific)" + ret = [] + ret.extend(self.tag_hold) + tag = TAGS.get('title%dClose'%self.level) + if tag: ret.append(tag) + #tag = TAGS.get('blockTitle%dClose'%self.level) + #if tag: ret.append(tag) + return ret def _save_toc_info(self): "Save TOC info, used by self.dump_marked_toc()" @@ -2876,7 +2949,8 @@ titrowopen = titrowopen + '\n' # Tex gotchas - if TARGET == 'tex': + # pst: added ltb + if TARGET == 'tex' or TARGET == 'ltb': if not self.border: rowopen = titrowopen = '' else: @@ -3472,6 +3546,9 @@ template = string.split(HEADER_TEMPLATE[target+'css'], '\n') else: template = string.split(HEADER_TEMPLATE[target], '\n') + + #pst: compose handouts if needed + template = doHandout(config) head_data = {'STYLE':[], 'ENCODING':''} for key in head_data.keys(): @@ -3488,8 +3565,9 @@ # Expand macros contents = MacroMaster(config=config).expand(headers[i]) # Escapes - on tex, just do it if any \tag{} present - if target != 'tex' or \ - (target == 'tex' and re.search(r'\\\w+{', contents)): + # pst: added ltb + if (target != 'tex' or target != 'ltb') or \ + ((target == 'tex' or target == 'ltb') and re.search(r'\\\w+{', contents)): contents = doEscape(target, contents) if target == 'lout': contents = doFinalEscape(target, contents) @@ -3567,6 +3645,21 @@ return string.split(template, '\n') +#pst: new function to create handouts of ltb slideshow +def doHandout(config): + target = config['target'] + if not HEADER_TEMPLATE.has_key(target): + Error("doHandout: Unknow target '%s'"%target) + template = HEADER_TEMPLATE[target] + + # change documentclass to use handout option + if (target == 'ltb'): + Debug('template before: %s'%template) + template = template.replace('\\documentclass{beamer}','\\documentclass[handout]{beamer}') + Debug('template after: %s'%template) + + return string.split(template, '\n') + def doCommentLine(txt): # The -- string ends a (h|sg|xht)ml comment :( txt = maskEscapeChar(txt) @@ -3584,6 +3677,8 @@ target = config['target'] cmdline = config['realcmdline'] typename = target + # pst: added ltb + if target == 'ltb': typename = 'LaTeX2e with latex-beamer class' if target == 'tex': typename = 'LaTeX2e' ppgd = '%s code generated by %s %s (%s)'%( typename,my_name,my_version,my_url) @@ -3617,7 +3712,8 @@ txt = string.replace(txt, '"', '"%s""'%ESCCHAR) # "\"" txt = re.sub('([|&{}@#^~])', '"\\1"',txt) # "@" txt = string.replace(txt, tmpmask, '"%s"'%(ESCCHAR*2)) # "\\" - elif target == 'tex': + # pst: added ltb + elif target == 'tex' or target == 'ltb': # Mark literal \ to be changed to $\backslash$ later txt = string.replace( txt, ESCCHAR, tmpmask) txt = re.sub('([#$&%{}])', ESCCHAR+r'\1' , txt) # \% @@ -3635,7 +3731,8 @@ elif target == 'man' : txt = string.replace(txt, '-', r'\-') elif target == 'sgml': txt = string.replace(txt, '[', '[') elif target == 'lout': txt = string.replace(txt, '/', '"/"') - elif target == 'tex' : + # pst: added ltb + elif target == 'tex' or target == 'ltb': txt = string.replace(txt, '_', r'\_') txt = string.replace(txt, 'vvvvTexUndervvvv', '_') # shame! return txt @@ -3850,6 +3947,21 @@ 'iso-8859-5' : 'latin5', 'iso-8859-9' : 'latin9', 'koi8-r' : 'koi8-r' + }, + 'ltb': { + # pst: idem for ltb than for tex + 'us-ascii' : 'ascii', + 'windows-1250': 'cp1250', + 'windows-1252': 'cp1252', + 'ibm850' : 'cp850', + 'ibm852' : 'cp852', + 'iso-8859-1' : 'latin1', + 'iso-8859-2' : 'latin2', + 'iso-8859-3' : 'latin3', + 'iso-8859-4' : 'latin4', + 'iso-8859-5' : 'latin5', + 'iso-8859-9' : 'latin9', + 'koi8-r' : 'koi8-r' } } # Normalization @@ -4008,7 +4120,8 @@ if re.match('^\s+$', rest): tag = "
%s
" %tag - if TARGET == 'tex': + # pst: added ltb + if TARGET == 'tex' or TARGET == 'ltb': tag = re.sub(r'\\b',r'\\\\b',tag) txt = string.replace(txt, '_', 'vvvvTexUndervvvv') @@ -4528,8 +4641,12 @@ ret.extend(BLOCK.blockout()) # Maybe close some opened title area? + # pst: use ltb specific title closing ;) if rules['titleblocks']: - ret.extend(TITLE.close_all()) + if TARGET == 'ltb': + ret.extend(TITLE.close_last()) + else: + ret.extend(TITLE.close_all()) # Maybe a major tag to enclose body? (like DIV for CSS) if TAGS['bodyOpen' ]: ret.insert(0, TAGS['bodyOpen'])