473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

HTML to LaTeX RE pattern and sub

Hi,

trying to make a small script which would translate wiki file into
LaTeX and when trying to translate possible HTML elements into LaTeX I
did this:

def latexEnvironments(matchobj):
print >>sys.stderr,str(matchobj.groups())
inStr = matchobj.group(1)
translDict = {'dl': ('\\begin{description}','\\end{description}'),
'ol': ('\\begin{enumerate}','\\end{enumerate}'),
'ul': ('\\begin{itemize}','\\end{itemize}'),
'blockquote': ('\\begin{quote}','\\end{quote}'),
'center': ('\\begin{center}','\\end{center}'),
'li': ('\\item',''),
'pre': ('\\begin{ttfamily}','\\end{ttfamily}')}
if translDict.has_key(inStr):
retTuple = translDict[inStr]
else:
retTuple = ('','')
if matchobj.group(0) == '/':
return retTuple[1]
else:
return retTuple[0]

def latexHeadings(matchobj):
print >>sys.stderr,str(matchobj.groups())
inStr = matchobj.groups[1]
translDict = {'h1': '\\section{}',
'h2': '\\subsection{}',
'h3': '\\subsubsection{}',
'h4': '\\subsubsubsection{}',
'h5': '\\paragraph{}'}
if translDict.has_key(inStr) and (matchobj.groups[0] != '/'):
return translDict[inStr]
else:
return ''

def latexEmptyElements(matchobj):
retString = ""
print >>sys.stderr,str(matchobj.groups())
inStr = matchobj.group(0)
translDict = {'br//': '\\\\',
'hr': '\\par{}\\hrulefill{}\\par{}'}
if translDict.has_key(inStr):
return translDict[inStr]
else:
return ''

[... snip ...]

# Remove superfluous HTML elements
reEnvironments =
re.compile(r'<(/?)(dl|ol|ul|address|blockquote|center|del\
|ins|div|isindex|noscript|p|pre)>',re.IGNORE)
reHeadings = re.compile(r'<(/?)(h1|h2|h3|h4|h5|h6)>',re.IGNORE)
reEmpty = re.compile(r'<(hr|br)\s*/?>',re.IGNORE)
body = reEnvironments.sub(latexEnvironments,body)
body = reHeadings.sub(latexHeadings,body)
body = reEmpty.sub(latexEmptyElements,body)

The problem is that apparently RE never matches (and no function is
thus called). Can anybody tell me what's wrong with my REs, please?

Thanks for any help,

Matej

Sep 23 '05 #1
0 1099

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Ramsden | last post by:
I maintain various specs and FAQs in manually edited HTML documents, and I'd very much like some simple way of automatic section numbering as in 2.1, 2.1.1, 2.1.2, 2.2 etc, with table of contents...
7
by: Jacek Generowicz | last post by:
:::Title::: A simple text markup utility :::/Title::: :::Section Introduction ::: I'm looking for something to help developers wirte documentation for bits of software they are writing. The...
1
by: Tom | last post by:
I need a very, very minimal LaTeX system on Windows. I only need to have the possibility to get DVI files out of my tex files (with minimal fonts). An I need it without any installer (no settings...
8
by: fortuneteller | last post by:
Hello, I'm quite new to python and Scipy. Anyway I want to use it to plot graphs. Does anybody know if there is the possibility to use Latex in SciPy's plotting functions like gplt? Thanks...
6
by: Jeff Thies | last post by:
I have a club newsletter that is currently distributed as a PDF. I'm considering converting this to html... Several problems ensue. 1) PDF's can be formatted for a page to fit on a sheet of...
36
by: sonnystarks | last post by:
I am trying to learn HTML and have obtained several books on the subject. However, I am confused with the proper way of going about it as most of these books give me the basic tags and then say...
0
by: Ramdas | last post by:
Any HTML to Latex module available in Python which I can use to convert HTML text to Latex Ramdas
15
by: Yogi | last post by:
Hi there, I have a quick question. In my html document, I want to make a new paragraph whenever I have a blank line in the html source. Using <p> and </pevery time is kind of cumbersome (I want...
5
by: vasan999 | last post by:
Basically, it should do all that any of the tools below and in addition, 1/ human readable output that maintains the text lines of the source, ie does not scramble the text lines or insert...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.