- Code: Select all
TextSelection textSelection = doc.findAllString(pattern, false, false)[0];
OfficeMath officeMath = new OfficeMath(doc);
officeMath.fromLatexMathCode(latex);
CharacterFormat characterFormat= new CharacterFormat();
characterFormat.setTextColor(Color.RED);
characterFormat.setFontSize(50f);
officeMath.applyCharacterFormat(characterFormat);
TextRange range = textSelection.getAsOneRange();
int index = range.getOwnerParagraph().getChildObjects().indexOf(range);
range.getOwnerParagraph().getChildObjects().insert(index, officeMath);
range.getOwnerParagraph().getChildObjects().remove(range);