From d95f8574ec670222f7236033e7b188c7b5a099ab Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Sun, 26 Jun 2011 14:50:18 -0400 Subject: v3: define latex \newcommands for some special characters (for sisu code) * \newcommands for some special characters to simplify dealing with them in sisu code \hardspace \caret \pipe \curlyopen \curlyclose \lt \gt \slash \backslash \underscore \exclaim --- data/doc/sisu/CHANGELOG_v3 | 4 ++- lib/sisu/v3/texpdf.rb | 18 +++++++------ lib/sisu/v3/texpdf_format.rb | 63 ++++++++++++++++---------------------------- 3 files changed, 35 insertions(+), 50 deletions(-) diff --git a/data/doc/sisu/CHANGELOG_v3 b/data/doc/sisu/CHANGELOG_v3 index 830bdf12..eb21f67e 100644 --- a/data/doc/sisu/CHANGELOG_v3 +++ b/data/doc/sisu/CHANGELOG_v3 @@ -31,7 +31,9 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_3.0.13.orig.tar.gz * colors, added cursor line & column * texpdf - * define \hardspace to simplify placing a hardspace (within a code block) + * define latex \newcommands for some special characters to simplify + dealing with them in sisu code \hardspace \caret \pipe \curlyopen + \curlyclose \lt \gt \slash \backslash \underscore \exclaim * provide backslash character in code block * ansi screen reporting include document language code diff --git a/lib/sisu/v3/texpdf.rb b/lib/sisu/v3/texpdf.rb index 0f16e991..522480fd 100644 --- a/lib/sisu/v3/texpdf.rb +++ b/lib/sisu/v3/texpdf.rb @@ -462,10 +462,6 @@ module SiSU_TeX dob else 'error' #should never occur end - if dob.tmp =~/<=curly/ #takes care of escaped curly braces, expand - sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,dob) - dob.tmp=sp_char.special_characters_curly(dob.tmp) - end dob=enclose(dob) unless dob.tmp =~/^$/ dob else @@ -533,10 +529,6 @@ module SiSU_TeX dob.tmp.gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*/,' \newline ') #% tread with care dob.tmp.gsub!(/(\.#{Tex[:tilde]}\S*\s*|<:\S+>|#{Mx[:fa_o]}.*?#{Mx[:fa_c]}|#{Mx[:gr_o]}.*?#{Mx[:gr_c]}||)/,' ') #% tread with care end - if dob.tmp =~/<=curly/ #takes care of escaped curly braces, expand - sp_char=SiSU_TeX_Pdf::Special_characters.new(@md,dob) - dob.tmp=sp_char.special_characters_curly(dob.tmp) - end dob end if dob.tmp =~/(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image\b)/m \ @@ -586,6 +578,16 @@ module SiSU_TeX \\newcommand{\\parasep}{\\\\ \\begin{center}*\\hspace{2em}*\\hspace{2em}*\\end{center} \\\\} \\newcommand{\\hardspace}{{~}} %\\newcommand{\\hardspace}{\\hspace{.5em}} +\\newcommand{\\caret}{{\\^{~}}} +\\newcommand{\\pipe}{{\\textbar}} +\\newcommand{\\curlyopen}{\{} +\\newcommand{\\curlyclose}{\}} +\\newcommand{\\lt}{{\UseTextSymbol{OML}{<}}} +\\newcommand{\\gt}{{\UseTextSymbol{OML}{>}}} +\\newcommand{\\slash}{{/}} +\\newcommand{\\underscore}{\\_} +\\newcommand{\\exclaim}{\\Verbatim{!}} +% (tilde hash amp affected by http) % \\sloppy \\begin{document} WOK diff --git a/lib/sisu/v3/texpdf_format.rb b/lib/sisu/v3/texpdf_format.rb index f7e63066..d7942121 100644 --- a/lib/sisu/v3/texpdf_format.rb +++ b/lib/sisu/v3/texpdf_format.rb @@ -983,7 +983,7 @@ WOK w.gsub!(/[\\]?~/,'<=tilde>') w.gsub!(/[#{Mx[:br_line]}#{Mx[:br_paragraph]}]/,' \newline ') #watch w.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>') #126 usual - w.gsub!(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'<=pipe>') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX + w.gsub!(/\\?\||#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'\pipe') #unless is=='code' #unless w=~/<~\d+;(?:[ohmu]|[0-6]:)\d+;\w\d+>/ # | SiSU not really special sisu character but done, also LaTeX if w !~/#{Mx[:rel_o]}/ \ and w !~/#{Mx[:gl_o]}#/ w.gsub!(/\#/,'<=hash>') @@ -1000,26 +1000,26 @@ WOK str.gsub!(/#{Mx[:br_eof]}/,'') str.gsub!(/#{Mx[:br_endnotes]}/,'') #problem sequence -> - str.gsub!(/&(?:nbsp);|#{Mx[:nbsp]}/,'<=hardspace>') unless is=='code' # < SiSU special character also LaTeX - str.gsub!(/&(?:lt|#060);/,'<=lt>') # < SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'<=gt>') # > SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'<=curlyopen>') # { SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'<=curlyclose>') # } SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>') # ~ SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'\#') # # SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!') # ! SiSU not really special sisu character but done, also LaTeX - str.gsub!(/(^|\s)\*\s/,'\1\asterisk ') # * should you wish to escape astrisk e.g. describing \*{bold}* - str.gsub!(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'\*') # * should you wish to escape astrisk e.g. describing \*{bold}* - str.gsub!(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-') # - SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+') # + SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,',') # + SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'<=amp>') #unless @txt=~/<:code>/ # / SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'<=slash>') # / SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'<=backslash>') # \ SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'<=underscore>') # _ SiSU special character also LaTeX - str.gsub!(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') # | SiSU not really special sisu character but done, also LaTeX - str.gsub!(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':') # : SiSU not really special sisu character but done, also LaTeX - str.gsub!(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'<=caret>') # ^ SiSU not really special sisu character but done, also LaTeX + str.gsub!(/&(?:nbsp);|#{Mx[:nbsp]}/,'\hardspace') unless is=='code' # < SiSU special character also LaTeX + str.gsub!(/&(?:lt|#060);/,'\lt') # < SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#(?:gt|062)#{Mx[:gl_c]}/,'\gt') # > SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'\curlyopen') # { SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'\curlyclose') # } SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/,'<=tilde>') # ~ SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'\#') # # SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!') # ! SiSU not really special sisu character but done, also LaTeX + str.gsub!(/(^|\s)\*\s/,'\1\asterisk ') # * should you wish to escape astrisk e.g. describing \*{bold}* + str.gsub!(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'\*') # * should you wish to escape astrisk e.g. describing \*{bold}* + str.gsub!(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-') # - SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#043#{Mx[:gl_c]}/,'+') # + SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#044#{Mx[:gl_c]}/,',') # + SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#038#{Mx[:gl_c]}/,'<=amp>') #unless @txt=~/<:code>/ # / SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'\slash') # / SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\textbackslash') # \ SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'<=underscore>') # _ SiSU special character also LaTeX + str.gsub!(/#{Mx[:gl_o]}#124#{Mx[:gl_c]}/,'|') # | SiSU not really special sisu character but done, also LaTeX + str.gsub!(/#{Mx[:gl_o]}#058#{Mx[:gl_c]}/,':') # : SiSU not really special sisu character but done, also LaTeX + str.gsub!(/#{Mx[:gl_o]}#094#{Mx[:gl_c]}|\^/,'\caret') # ^ SiSU not really special sisu character but done, also LaTeX ##watch placement, problem sequence ^ str.gsub!(/&atild;<\/font><\/sup>/,' ') str.gsub!(/\\copy(right|mark)?/,'<=copymark>') # ok problem with superscript @@ -1043,8 +1043,6 @@ WOK str.gsub!(/\\~(\[)/,'{$\tilde$}\1') str.gsub!(/(\])\\~/,'\1{$\tilde$}') str.gsub!(/<=tilde>/,'{$\tilde$}') - str.gsub!(/<=pipe>/,'{\textbar}') - str.gsub!(/<=caret>/,'{\^{~}}') str.gsub!(/<=hash>/,'{\#}') else str.gsub!(/ |#{Mx[:nbsp]}/,'~') # ~ character for hardspace @@ -1099,44 +1097,27 @@ WOK def xetex_special_characters_3(str) str.gsub!(/])/,'\1') # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder str.gsub!(/([^<][^b][^r]\s+)\/>/,'\1') # clean up, incredibly messy :-( footnote indents, problems if match exists in ordinary paragraphs? check! Work Area 200501 a bit tricky as must be able to match multiple times, and to clean remainder - #problem sequence (another kludge) -> - str.gsub!(/<=lt>/m,'{\UseTextSymbol{OML}{<}}') - str.gsub!(/<=gt>/m,'{\UseTextSymbol{OML}{>}}') - str.gsub!(/<=underscore>/,'\_') while str =~/(https?:\/\/\S+?)(?:<=tilde>\S+)+/ #tilde in urls \href treated differently from text #FIX str.gsub!(/(https?:\/\/\S+?)(?:<=tilde>(\S+))+/,'\1~\2') end str.gsub!(/<=tilde>/,'{$\tilde$}') - str.gsub!(/<=pipe>/,'{\textbar}') - str.gsub!(/<=caret>/,'{\^{~}}') - str.gsub!(/<=exclaim>/,'\Verbatim{!}') str.gsub!(/(https?:\/\/\S+?)(?:(?:<=hash>)(\S+))+/,'\1#\2') #hash in urls \href treated differently from text #FIX str.gsub!(/<=hash>/,'{\#}') - str.gsub!(/<=hardspace>/,'{~}') #changed ... 2005 while str =~/(https?:\/\/\S+?)(?:<=amp>\S+)+/ #amp in urls \href treated differently from text #FIX str.gsub!(/(https?:\/\/\S+?)(?:<=amp>(\S+))+/,'\1&\2') end str.gsub!(/<=amp>/,'{\\\&}') #changed ... 2005 - str.gsub!(/<=slash>/,'{/}') - str.gsub!(/<=backslash>/,'{\textbackslash}') str.gsub!(/<=copymark>\s*(.+)/, '^\copyright \textnormal{\1} \2') # watch likely to be problematic str end - def special_characters_curly(str) - str.gsub!(/<=curlyopen>/,'\{') - str.gsub!(/<=curlyclose>/,'\}') - str - end def special_characters_code_fix(str) - str.gsub!(/<=hardspace>/,'{~}') - str.gsub!(/<=pipe>/,'{\textbar}') str.gsub!(/<=tilde>/,'{$\tilde$}') str end def special_characters_unsafe_1(str) #depreciated, make obsolete # some substitutions are sequence sensitive, rearrange with care. - str.gsub!(/\\backslash (copyright|clearpage|newpage)/,"\\\\\\1") #kludge bad solution, find out where tail is sent through specChar ! + str.gsub!(/\\textbackslash (copyright|clearpage|newpage)/,"\\\\\\1") #kludge bad solution, find out where tail is sent through specChar ! str end def special_characters #special characters - some substitutions are sequence sensitive, rearrange with care. -- cgit v1.2.3