Changeset 1229 in lmdz_wrf
- Timestamp:
- Oct 22, 2016, 3:59:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/generic_tools.py
r1228 r1229 37 37 ####### Content 38 38 # ASCII_LaTeX: Function to transform from an ASCII character to LaTeX codification 39 # ASCII_to: Function to provide the equivalence text to a given lenguage omitting certain characters 39 40 # Capturing: Class to capture the standard output from a function 40 41 # CFmonthU_daysU: Function to transform from a CF date series with units as 'months since [DATE]' to 'days since [DATE]' … … 9395 9396 return newmat 9396 9397 9398 def ASCII_to(text,to,nochg=None): 9399 """ Function to provide the equivalence text to a given lenguage omitting certain characters 9400 text= text to transform 9401 to= language to use 9402 'tex': LaTeX 9403 nochg: a list with characters to be omitted 9404 >>> ASCII_to('à $353\pol', 'tex') 9405 \`a\$353\textbackslashpol 9406 >>> ASCII_to('à $353\pol', 'tex', ['$']) 9407 \`a$353\textbackslashpol 9408 """ 9409 fname = 'ASCII_to' 9410 langs = ['tex'] 9411 9412 9413 texchars = {'\\': '\\textbackslash', \ 9414 'á': "\\'a", 'é': "\\'e", 'Ã': "\\'i", 'ó': "\\'o", 'ú': "\\'u", \ 9415 'à ': "\\`a", 'Ú': "\\`e", 'ì': "\\`i", 'ò': "\\`o", 'ù': "\\`u", \ 9416 'â': "\\^a", 'ê': "\\^e", 'î': "\\^i", 'ÃŽ': "\\^o", 'û': "\\^u", \ 9417 'À': '\\"a', 'ë': '\\"e', 'ï': '\\"i', 'ö': '\\"o', 'ÃŒ': '\\"u', \ 9418 'ç': '\c{c}', 'ñ': '\~{n}', \ 9419 'Ã': "\\'A", 'Ã': "\\'E", 'Ã': "\\'I", 'Ã': "\\'O", 'Ã': "\\'U", \ 9420 'Ã': "\\`A", 'Ã': "\\`E", 'Ã': "\\`I", 'Ã': "\\`O", 'Ã': "\\`U", \ 9421 'Ã': "\\^A", 'Ã': "\\^E", 'Ã': "\\^I", 'Ã': "\\^O", 'Ã': "\\^U", \ 9422 'Ã': '\\"A', 'Ã': '\\"E', 'Ã': '\\"I', 'Ã': '\\"O', 'Ã': '\\"U', \ 9423 'Ã': '\\c{C}', 'Ã': '\\~{N}', \ 9424 '¡': '!`', '¿': '¿`', '%': '\\%', '#': '\\#', '&': '\\&', '$': '\\$', \ 9425 '_': '\\_', '·': '\\textperiodcentered', '<': '$<$', '>': '$>$', \ 9426 'ï': '*', 'ª': '$^{a}$', 'º': '$^{o}$', '°': '$^{\\circ}$', '\n': '\\\\\n', \ 9427 '\t': '\\medskip', 'â': '``', 'â': '\'\'', '^': '\^'} 9428 9429 if to == 'tex': 9430 chars = texchars 9431 # Specific first characters to change 9432 firstchars = ['\\'] 9433 else: 9434 print errormsg 9435 print ' ' + fname + ": language '" + to + "' not ready !!" 9436 print ' available languages:', langs 9437 quit(-1) 9438 9439 if nochg is not None: 9440 for noc in nochg: 9441 if not chars.has_key(noc): 9442 print errormsg 9443 print ' ' + fname + ": language '" + to + "' does not have '" + \ 9444 noc + "' to change !!" 9445 quit(-1) 9446 chars.pop(noc) 9447 if searchInlist(firstchars,noc): firstchars.remove(noc) 9448 9449 newtext = text + '' 9450 for char in firstchars: 9451 newtext = newtext.replace(char,chars[char]) 9452 chars.pop(char) 9453 9454 for char in chars.keys(): 9455 newtext = newtext.replace(char,chars[char]) 9456 9457 return newtext 9458 9397 9459 def ASCII_LaTeX(ln): 9398 9460 """ Function to transform from an ASCII character to LaTeX codification … … 9417 9479 newln = newln.replace('â', "\\^a") 9418 9480 newln = newln.replace('ê', "\\^e") 9481 9419 9482 newln = newln.replace('î', "\\^i") 9420 9483 newln = newln.replace('ÃŽ', "\\^o") … … 9488 9551 >>> latex_text('WRF_LMDZ$_{current}^{AR40}$') 9489 9552 WRF\_LMDZ$_{current}^{AR40}$ 9553 >>> latex_text('LluÃs Fita$_{1976/02/17}$') 9554 Llu\'is Fita$_{1976/02/17}$ 9490 9555 """ 9491 9556 fname = 'latex_text' … … 9587 9652 latextext = headtxt + '\\$' + tailtxt 9588 9653 9654 NOchange = ['_', '^', '\\', '&', '$'] 9655 latextext = ASCII_to(latextext, 'tex', NOchange) 9656 9589 9657 return latextext 9590 9658
Note: See TracChangeset
for help on using the changeset viewer.