Hola manooooh,
Llevas razón, no sirve. El principal inconveniente que veo es que matlab no reconoce los espacios.
El otro principal inconveniente es que hay comandos que son incompatibles.
Suponiendo que se salvan estos dos inconvenientes, esto de aquí funciona me parece:
clear, clc
str='$cos\theta$\\ Pero si $$x$$ entonces \\ \begin{bmatrix}a\\ b\\ c\end{bmatrix}\\ \begin{bmatrix}a\\ b\\ c\end{bmatrix}\\ $\int$ \\ si \\'
v=strfind(str,'$');
for k=1:length(v)
str=insertAfter(str,v(k),'$');
v=v+1;
end
v=strfind(str,'$$$$');
for k=1:length(v)
str=eraseBetween(str,v(k),v(k)+1);
v=v-2;
end
u=strfind(str,'\begin');
w=strfind(str,'\end');
v=strfind(str,'\\');
for n=1:length(v)
for k=1:length(u)
if u(k)<v(n) && v(n)<w(k)
break
elseif v(n)<u(k)
str=eraseBetween(str,v(n),v(n)+1);
u=u-2;
w=w-2;
v=v-2;
break
end
end
end
for n=1:length(v)
if v(n)>w(end)
z=v(n:end);
break
end
end
for k=1:length(z)
str=eraseBetween(str,z(k),z(k)+1);
z=z-2;
end
str
Conclusión consecuencia de los inconvenientes que has indicado:
El código sirve para poco o nada.
Sin embargo:
Me ha servido de gimnasia mental.
Para resolver de verdad el problema:
Usar el mismo editor en un lado y en otro. Desaparecen los problemas de incompatibilidad.
Si todo el mundo hablase el mismo idioma, nos ahorraríamos tener que traducir entre idiomas.
Saludos.
(PS: No me hagas pensar más en esto porque he estado unas horas liado y no debería!)