Ok, I’ve found a simple solution: replace everything between and with empty string and disable WHITE_SPACE rule.
/**
* Empty string of length len
* @param leng
* @return
*/
public static String padString(int leng) {
StringBuffer str= new StringBuffer();;
for (int i =0; i <leng; i++) str.append(" ");
return str.toString();
}
/**
* Replace latex tags preserving document structure
* @param text
* @return
*/
public static String modifyLatexTags(String text) {
// replace between $ and $
Pattern p = Pattern.compile("\\$[^\\$]*\\$");
Matcher m = p.matcher(text);
while(m.find()){
String d = text.substring(m.start(), m.end());
String empty=padString(d.length());
text = text.replace(d, empty);
}
return text;
}
best, Sergei