S = sprintf('New percent OS = $%.2f$ %%',percentOS)
However, this gives an error for the variable insertion portion of text,
What is the full and exact text of the error message you received (all the text displayed in red)? As you can see from the code segment above, it does work at least in this simple case. If you have a more complicated example that throws the error please show it.
I have also tried using the latex syntax for a percent sign, which would be:
S2 = sprintf('New percent OS = $%.2f$ $\%$',percentOS)
This gave a different error, but nonetheless did not work.
So as you can see this issues a warning but does not throw an error. Ah, I think I might know what's going on. Is the following the warning/error that you are asking about?
text(0.5, 0.5, S, 'Interpreter', 'LaTeX')
S3 = sprintf('New percent OS = $%.2f$ \\%%',percentOS)
text(0.5, 0.5, S3, 'Interpreter', 'LaTeX')
The \\ in the format used to create S3 transforms into a \ in S3 itself just like the %% puts a % in the char array. The LaTeX interpreter interprets the \% as a percent sign. You could achieve the same result with string operations on S if you can't change the format.
S4 = replace(S, '%', '\%')