I don't know if I entirely follow the question- rendering outside the plot is possible with the code you already have. The issue is with the LaTeX renderer in Plots.jl. Replacing
str = L"\begin{bmatrix}
1& 2\\
3& 4\\
\end{bmatrix}"
with str = L"y = \sin(x)"
, gives us this:
after adjusting the position of str
using the x and y parameters of the annotate!
call.
Reading the documentation for LaTeXStrings.jl, it states:
FAQ: Not a LaTeX renderer
LaTeXStrings does not do any rendering — its sole purpose is to make it easier to enter LaTeX-rendered strings without typing a lot of backslash escapes, as well as providing a type to tell display backends to use LaTeX rendering if possible.
*Other packages like plotting software, Jupyter notebooks, Pluto, etcetera, are responsible for the LaTeX rendering (if any). For example, they might use MathJax, MathTeXEngine.jl, or other renderers. LaTeXStrings only provides the LaTeX text to these backend, and has no influence on what LaTeX features (if any) are supported. [emphasis mine]
Running equivalent code using GLMakie, I get an error that \begin isn't supported. I can't find the renderer used by Plots.jl in their source code, but it seems clear that whichever one they use, it doesn't support the LaTeX that you're trying within str
.