MATLAB: How to turn off the LaTeX interpreter in the legend within MATLAB

interpreterlatexlegendMATLABofftexunderscore

I am displaying strings with underscores "_" in the legend on my plot. When the LaTex interpreter is used, the underscores are causing subscript letters. I would like to override the LaTeX interpreter so the legend appears exactly as the input string.

Best Answer

The LaTeX interpreter can be turned off for a text object by setting the 'Interpreter' property to 'none'. You can specify the interpreter to be used with the legend using the 'Interpreter' parameter/value pair input argument to the LEGEND function. For example,
figure; plot(1:10)
l = legend({'test_line'}, 'Interpreter', 'none');
Note that the legend string(s) must be enclosed in a cell array.
You can also set the 'Interpreter' property after the creation of the legend:
figure; plot(1:10)
l = legend('test_line');
set(l, 'Interpreter', 'none')