### Question:
MathMLUtils { public static Multiset<String> extractIdentifiersFromTex(String tex, boolean useTeX, String url) { if (useTeX) { try { Multiset<String> identifiers = TexInfo.getIdentifiers(tex, url); identifiers.removeIf(x -> x.equals("\\infty") || x.startsWith("\\operatorname")); if (summarizeSubscripts) { for (String identifier : identifiers.elementSet()) { if (identifier.matches("(.*?)_\\{[a-zA-Z0-9]\\}$")) { identifiers.remove(identifier, Integer.MAX_VALUE); identifiers.add(identifier.replaceAll("(.*?)_\\{[a-zA-Z0-9]\\}$", "$1_")); } } } return identifiers; } catch (XPathExpressionException | ParserConfigurationException | IOException | SAXException | TransformerException e) { e.printStackTrace(); return HashMultiset.create(); } } String mathML = texToMathML(tex); LOGGER.debug("converted {} to {}", tex.replaceAll("\\s+", " "), mathML); return extractIdentifiersFromMathML(mathML, false, false); }  static String getEngine(); static void setEngine(String engine); static Multiset<String> extractIdentifiers(MathTag math, Boolean useTeXIdentifiers, String url); static Multiset<String> extractIdentifiersFromTex(String tex, boolean useTeX, String url); static Multiset<String> extractIdentifiersFromMathML(String mathML, Boolean useTeXIdentifiers, boolean useBlacklist); static boolean isNumeric(String id); static String texToMathML(String tex); static String cleanTexString(String tex); final static Set<String> BLACKLIST; }### Answer:
@Test public void extractFromTex_simple() { String tex = "x^2 + y^2 = z^2"; Set<String> identifiers = MathMLUtils.extractIdentifiersFromTex(tex, false, "").elementSet(); Set<String> expected = ImmutableSet.of("x", "y", "z"); assertEquals(expected, identifiers); }
@Test public void extractFromTex_subscripts() { String tex = "\\sigma_1 + \\sigma_2 = r_1"; Set<String> identifiers = MathMLUtils.extractIdentifiersFromTex(tex, false, "").elementSet(); Set<String> expected = ImmutableSet.of("σ_1", "σ_2", "r_1"); assertTrue(identifiers.containsAll(expected)); }
@Test public void extractFromTex_superscriptIndentifier() { String tex = "\\sigma^x"; Set<String> identifiers = MathMLUtils.extractIdentifiersFromTex(tex, false, "").elementSet(); Set<String> expected = ImmutableSet.of("σ", "x"); assertTrue(identifiers.containsAll(expected)); }
@Test public void extractFromTex_capturesMultipleOccurrences() { String tex = "\\sigma^2 + \\sigma + b"; Multiset<String> identifiers = MathMLUtils.extractIdentifiersFromTex(tex, false, ""); Multiset<String> expected = HashMultiset.create(Arrays.asList("σ", "σ", "b")); assertEquals(expected, identifiers); }
@Test public void extractFromTex_oneIdTwoOccurrences_sizeIs2() { String tex = "\\sigma + \\sigma"; Multiset<String> identifiers = MathMLUtils.extractIdentifiersFromTex(tex, false, ""); assertEquals(2, identifiers.size()); }
@Test public void extractFromTex_boldText() { String tex = "\\mathbf r"; Set<String> identifiers = MathMLUtils.extractIdentifiersFromTex(tex, false, "").elementSet(); Set<String> expected = ImmutableSet.of("r"); assertTrue(identifiers.containsAll(expected)); }