473,545 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 latexEnvironmen ts(matchobj):
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.group( 1)
translDict = {'dl': ('\\begin{descr iption}','\\end {description}') ,
'ol': ('\\begin{enume rate}','\\end{e numerate}'),
'ul': ('\\begin{itemi ze}','\\end{ite mize}'),
'blockquote': ('\\begin{quote }','\\end{quote }'),
'center': ('\\begin{cente r}','\\end{cent er}'),
'li': ('\\item',''),
'pre': ('\\begin{ttfam ily}','\\end{tt family}')}
if translDict.has_ key(inStr):
retTuple = translDict[inStr]
else:
retTuple = ('','')
if matchobj.group( 0) == '/':
return retTuple[1]
else:
return retTuple[0]

def latexHeadings(m atchobj):
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.groups[1]
translDict = {'h1': '\\section{}',
'h2': '\\subsection{} ',
'h3': '\\subsubsectio n{}',
'h4': '\\subsubsubsec tion{}',
'h5': '\\paragraph{}' }
if translDict.has_ key(inStr) and (matchobj.group s[0] != '/'):
return translDict[inStr]
else:
return ''

def latexEmptyEleme nts(matchobj):
retString = ""
print >>sys.stderr,st r(matchobj.grou ps())
inStr = matchobj.group( 0)
translDict = {'br//': '\\\\',
'hr': '\\par{}\\hrule fill{}\\par{}'}
if translDict.has_ key(inStr):
return translDict[inStr]
else:
return ''

[... snip ...]

# Remove superfluous HTML elements
reEnvironments =
re.compile(r'<(/?)(dl|ol|ul|add ress|blockquote |center|del\
|ins|div|isinde x|noscript|p|pr e)>',re.IGNORE)
reHeadings = re.compile(r'<(/?)(h1|h2|h3|h4| h5|h6)>',re.IGN ORE)
reEmpty = re.compile(r'<( hr|br)\s*/?>',re.IGNORE)
body = reEnvironments. sub(latexEnviro nments,body)
body = reHeadings.sub( latexHeadings,b ody)
body = reEmpty.sub(lat exEmptyElements ,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 1104

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

Similar topics

4
2001
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 generation plugged into the start of the document so that each section can be accessed via a link (and also maybe automatic footnote numbering). ...
7
2171
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 main (initially only) presentation format will be HTML. The idea is to allow the author to write a plain text file containing the text he wishes to...
1
2069
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 in registry and no or less enviroment variables). I know this was asked a few time here but I haven't found any suitable information yet. I posted...
8
3383
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 for your help, Matthias
6
1874
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 8.5 * 11 paper. I'm not sure how to this in HTML. 2) A PDF can be set to print all pages. I'm not sure how to do this with html either. Suggesting...
36
3002
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 they will soon be deprecated and advise using CSS stylesheets. Which comes first? Do I learn the old tags and then "upgrade" to CSS or just bypass the...
0
925
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
19860
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 to do it the LaTeX way). Is it possible at all? Thanks for your time, Yogi
5
2028
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 newlines unnecessarily or removes them. inserts minimal latex elements. 2/ maintains cross-links, ie convert <href to \ref and <name= to \label
0
7486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7776
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6001
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
4965
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3456
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1905
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.