Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have one input file which will be used for LaTeX and HTML (Java program). Input file has HTML markups like

<b></b> for bold.
<li></li> for list.

How can I convert above markup into LaTeX markup while generating pdf?

share|improve this question
3  
Consider reading How do I convert HTML to LaTeX? –  Werner Jan 10 '13 at 4:31
    
I don't want to convert HTML into latex but jsut need to modify some text. –  user15662 Jan 10 '13 at 5:59
    
So you want LaTeX to convert (say) <b>hello</b> to {\bfseries hello} or \textbf{hello} within a certain piece of your code? That is, keep the code HTML but interpret it in a different way? Is this because you don't want to change the HTML mark-up to LaTeX, I guess, to easily transition between the two formats. –  Werner Jan 10 '13 at 6:04

1 Answer 1

up vote 2 down vote accepted

Did you try sed?

cat test 
<b>Bold text</b>. Regular text, <i>italics</i>, <tt>teletype</tt>, regular.
Nested: <b>Bold <i>bold italics</i> again bold</b> 

sed -e 's|<b>\(.*\)</b>|\\textbf{\1}|g' -e 's|<i>\(.*\)</i>|\\textit{\1}|g' -e 's|<tt>\(.*\)</tt>|\\texttt{\1}|g' test
\textbf{Bold text}. Regular text, \textit{italics}, \texttt{teletype}, regular.
Nested: \textbf{Bold \textit{bold italics} again bold} 
share|improve this answer
    
@ Eddy_Em your answer is very useful, can we convert <ol><li></li></ol> also into latex markup. –  user15662 Jan 16 '13 at 4:26
    
Yes: sed -e 's|<ol>\(.*\)</ol>|\\begin{enumerate}\n\1\\end{enumerate}|g' -e 's|<li>\([^<]*\)</li>|\t\\item \1\n|g' but if there could be other tags between <li></li> regexp would be more complex. Another variant is to remove all </li> and substitute by /item only <li>. Also this construction will not work for nested lists. –  Eddy_Em Jan 16 '13 at 5:47
    
Above script does not convert ul or ol into \itemize –  user15662 Jan 16 '13 at 8:48
    
echo "<ul><li>1a</li><li>2a</li></ul>" | sed -e 's|<ul>|\\begin{enumerate}|g' -e 's|</ul>|\\end{enumerate}|g' -e 's|<li>|\\item |g' -e 's|</li>||g' \begin{enumerate}\item 1a\item 2a\end{enumerate} –  Eddy_Em Jan 16 '13 at 9:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.