Last active
May 6, 2017 11:27
-
-
Save Arth-ur/a0ab7470bc0230bf4c22d2262cf88611 to your computer and use it in GitHub Desktop.
KVF -- Key Value File to Latex Lookuptable File in Matlab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\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