+
+ // Easy case: the command is a complete entry of unicodesymbols.
+ for (const auto & unicodeSymbol : unicodesymbols) {
+ if (mathmode) {
+ for (const auto & command : unicodeSymbol.second.mathCommands()) {
+ if (command == cmd) {
+ docstring value;
+ value += unicodeSymbol.first;
+ needsTermination = !unicodeSymbol.second.mathNoTermination();
+ return value;
+ }
+ }
+ }
+ if (textmode) {
+ for (const auto & command : unicodeSymbol.second.textCommands()) {
+ if (command == cmd) {
+ docstring value;
+ value += unicodeSymbol.first;
+ needsTermination = !unicodeSymbol.second.textNoTermination();
+ return value;
+ }
+ }
+ }
+ }
+
+ // Otherwise, try to map as many commands as possible, matching prefixes of the command.