I always have trouble exporting handmade Stata matrices to Latex when I want to use math in the rowtitles. Here is a good example, below. The command frmttable allows me to specify the row title that I want, but it converts "_" to "\_" in the .tex file, and there is no way to stop this (i.e. I can't use substitute(\_ _) as I do with esstab). As far as I can see, outtable does not provide options for specifying row or column titles, you have to provide the names directly to the matrix. However, Stata deems my matrix name too long. (And in fact, even if I instead write matrix rownames Kest = "$ K $") the dollar signs do not carry through, despite the asis option.)

So neither of these methods allows me to properly export my matrix with the titles I want. Is there some work-around, or some other export method I don't know about?

Code:
clear matrix
local rows = 1
local cols 2
capture matrix Kest = J(`rows',`cols',.)
mat Kest[1,1]= 1
mat Kest[1,2]= 2

% Try with frmttable
frmttable using "${TABLES}/Tab_Kest_A.tex", ///
    tex statmat(Kest) sdec(3) fragment replace ///
    ctitle("", "First Est","Second Est") ///
    rtitle("$ K \equiv \phi_{\varepsilon} / \phi_{\gamma x}$")
    
% Try with outtable
matrix rownames Kest = "$ K \equiv \phi_{\varepsilon} / \phi_{\gamma x}$"
matrix colnames Kest = "First Est" "Second Est"
outtable using "${TABLES}/Tab_Kest_B", ///
    mat(Kest) replace asis