Skip to content

Instantly share code, notes, and snippets.

@Arth-ur
Last active May 6, 2017 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arth-ur/a0ab7470bc0230bf4c22d2262cf88611 to your computer and use it in GitHub Desktop.
Save Arth-ur/a0ab7470bc0230bf4c22d2262cf88611 to your computer and use it in GitHub Desktop.
KVF -- Key Value File to Latex Lookuptable File in Matlab
kvffile = 'output/example.kvf';
texfile = 'output/example.tex';
diary(kvffile);
disp(['value1 = ' num2str(value1)]);
disp(['value2 = ' num2str(value2)]);
disp(['value3 = ' num2str(value3)]);
diary off;
fclose('all');
kvf2tex(kvffile, texfile, 'example'); % to latex
delete(kvffile);
function kvf2tex(fin, fout, rootkey)
if nargin > 2
rootkey = [rootkey '.'];
else
rootkey = '';
end
TEMPLATE = '\\@lookupPut{%s}{%s}\n';
hfin = fopen(fin, 'r');
hfout = fopen(fout, 'w+');
data = textscan(hfin, '%s = %s');
keys = data{1,1};
values = data{1,2};
fprintf(hfout, '\\makeatletter\n');
for i = 1:length(keys)
fprintf(hfout, TEMPLATE,...
[rootkey cell2mat(keys(i))], cell2mat(values(i)));
end
fprintf(hfout, '\\makeatother\n');
fclose(hfin);
fclose(hfout);
end
\makeatletter
\newcommand{\get}[1]{%
\@ifundefined{lookup@#1}{%
\PackageError{lookup}{No #1 key in lookup}{%
Key #1 was not found in lookup. %
You can insert it with \string\lookupPut{key}{value}.%
}%
}{%
\@nameuse{lookup@#1}%
}%
}
\newcommand{\@lookupPut}[2]{%
\@namedef{lookup@#1}{#2}%
}
\makeatother
\newcommand{\applysignrule}[1]{%
\StrSubstitute{#1}{+-}{-}%
}
%% Usage: \get{example.value1}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment