title: Converting HTML to another syntax (LaTeX) with PHP
body: <p>I'm trying to do a custom HTML to LaTeX converter, which uses Wordpress posts as a source. </p>
  
  <p>Basically, it needs to do some "replacing", like:</p>
  
  <pre><code>&lt;h2&gt;H2 Title&lt;/h2&gt;
  &lt;p&gt;Text text text&lt;/p&gt;
  &lt;img src="/image.png" alt="Image ALT tag" \&gt;
  </code></pre>
  
  <p>To this</p>
  
  <pre><code>   \begin{document}
  
     \section{H2 Title}
  
     Text text text
  
     \shorthandoff{=}
     \begin{figure}[H]
     \centering
     \includegraphics[scale=0.7]{./img/image.png}
     \caption{Image ALT tag}
     \end{figure}
     \shorthandon{=}
  
     \end{document}
  </code></pre>
  
  <p>Which approach should I use? Is there a HTML DOM parser <strike>that allows replacements like this</strike>? Or other suggestions? </p>
  
  <p>Update: Is there any way to walk <em>properly</em> in HTML DOM tree in PHP? I tried RecursiveDOMIterator (http://stackoverflow.com/questions/4431142/loop-through-all-elements-of-body-tags-using-dom) but I can't get a successfull result.</p>
  
  <p>Thanks.</p>