Created
December 31, 2012 11:10
-
-
Save zr-tex8r/4419089 to your computer and use it in GitHub Desktop.
LaTeX: Using TeX as a calculator
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
\documentclass{minimal} | |
\batchmode % suppress terminal output | |
\usepackage{expl3}[2012/09/05] | |
\errorstopmode % resume terminal output | |
\ExplSyntaxOn | |
%% calculator repl loop | |
\tl_new:N \l_tchcl_input_tl | |
\tl_new:N \l_tchcl_answer_tl | |
\bool_new:N \l_tchcl_quit_bool | |
\group_begin: | |
\char_set_catcode_active:N \* | |
\cs_gset:Nn \tchcl_readin: | |
{ | |
\ior_get_str:NN \c_term_ior * | |
\tl_set_eq:NN \l_tchcl_input_tl * | |
} | |
\group_end: | |
\bool_until_do:Nn \l_tchcl_quit_bool | |
{ | |
\tchcl_readin: | |
\tl_if_blank:VTF \l_tchcl_input_tl | |
{ \bool_set_true:N \l_tchcl_quit_bool } | |
{ | |
\tl_set:Nf \l_tchcl_answer_tl { \fp_to_tl:n { \l_tchcl_input_tl } } | |
\iow_term:x { -> \l_tchcl_answer_tl } | |
} | |
} | |
\ExplSyntaxOff | |
\stop % quit immediately | |
\begin{document} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment