Rewrote name2tex routine and fixed bug.

time-shift
Stéphane Adjemian (Scylla) 2013-11-22 16:08:23 +01:00
parent 1fe3e4bc77
commit d02171080c
1 changed files with 33 additions and 63 deletions

View File

@ -23,83 +23,53 @@ if nargin<2
info = 0;
end
if iscell(name)
nn = length(name);
tex = cell(nn,1);
else
nn = 1;
if info
if iscell(name)
nn = length(name);
else
nn = 1;
end
end
for i=1:nn
if info
tex = regexprep(name, '_', '\\_');
if info
for i=1:nn
if iscell(name)
tex(i) = {name{i}};
id = findstr(name{i},'_');
len = length(tex{i});
texname = tex{i};
else
tex = name;
id = findstr(name,'_');
len = length(tex);
texname = tex;
end
if isempty(id)
continue
end
n = length(id);
if id(1)==1
if iscell(name)
tex(i) = {['\_', tex{i}(2:end)]};
else
tex = ['\_', tex(2:end)];
idx = strfind(texname,'_');
ndx = length(idx);
ntx = length(texname);
if ndx
gotonextcondition = 1;
if isequal(ndx,1) && ~isequal(idx,2) && ~isequal(idx,ntx)
texname = [ texname(1:idx-2) '_{' texname(idx+1:end) '}'];
gotonextcondition = 0;
end
if n>1
id = id(2:end)+1;
n = n-1;
len = len+1;
else
continue
if gotonextcondition && isequal(ndx,2) && ~isequal(idx(1),2) && isequal(idx(2),ntx)
texname = [ texname(1:idx(1)-2) '_{' texname(idx(1)+1:end) '}' ];
gotonextcondition = 0;
end
end
if id(end)==len
if iscell(name)
tex(i) = {[tex{i}(1:end-1) '\_']};
else
tex = [tex(1:end-1) '\_'];
if gotonextcondition && isequal(ndx,2) && idx(2)<ntx
texname = [ texname(1:idx(2)-2) '_{' texname(idx(2)+1:end) '}' ];
gotonextcondition = 0;
end
if n>1
id = id(1:end-1);
n = n-1;
else
continue
end
end
if n==1
if iscell(name)
tex(i) = {[ tex{i}(1:(id-1)) '_{' tex{i}((id+1):end) '}' ]};
else
tex = [ tex(1:(id-1)) '_{' tex((id+1):end) '}' ];
end
continue
else
for j=1:n-1
if iscell(name)
tex(i) = {[tex{i}(1:id(j)-1) '\_' tex{i}((id(j)+1):end)]};
else
tex = [tex(1:id(j)-1) '\_' tex((id(j)+1):end)];
if gotonextcondition && ndx>2
if idx(end)<ntx
texname = [ texname(1:idx(end)-2) '_{' texname(idx(end)+1:end) '}' ];
else
texname = [ texname(1:idx(end-1)-2) '_{' texname(idx(end-1)+1:end) '}' ];
end
id = id(2:end)+1;
end
if iscell(name)
tex(i) = {[tex{i}(1:(id-1)) '_{' tex{i}((id+1):end) '}']};
tex(i) = { texname };
else
tex = [tex(1:(id-1)) '_{' tex((id+1):end) '}'];
tex = texname;
end
end
else
if iscell(name)
tex(i) = {strrep(name{i}, '_', '\_')};
else
tex = strrep(name, '_', '\_');
end
end
end