code: public static String latexPreProcessing(String latex) {
          LOG.debug(" Pre-Processing for:  " + latex);
  
          if (latex.contains("subarray")) {
              latex = latex.replaceAll("subarray", "array");
              LOG.trace(" Eval replacement of subarray: " + latex);
          }
  
          latex = latex.replaceAll(POM_BUG_AVOIDANCE_UNDERSCORE, "_{$1}");
          LOG.trace("Surround underscore:  " + latex);
  
          latex = latex.replaceAll(SINGLE_AND, TMP_SINGLE_AND);
          latex = HtmlEscape.unescapeHtml(latex);
          latex = latex.replaceAll(TMP_SINGLE_AND, " & ");
          LOG.trace("HTML Unescaped:       " + latex);
  
          latex = latex.replaceAll(LATEX_COMMENTED_LINEBREAK, "");
          LOG.trace("Commented linebreaks: " + latex);
  
          latex = latex.replaceAll(ELEMINATE_ENDINGS, "");
          latex = latex.replaceAll(ELEMINATE_STARTS, "");
          latex = latex.replaceAll(ELEMINATE_SIMPLE_STARTS, "");
          latex = latex.replaceAll(ELEMINATE_SIMPLE_ENDS, "");
          LOG.trace("Replace bad end/start:" + latex);
          LOG.debug("Finalize Pre-Processing for POM-Tagger: " + latex);
  
          return latex;
      }
docs: Pre processing mathematical latex expressions with
  several methods.
  
  @param latex raw latex input
  @return pre processed latex string