Skip to content

Instantly share code, notes, and snippets.

@zr-tex8r
Created December 31, 2012 11:10
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 zr-tex8r/4419089 to your computer and use it in GitHub Desktop.
Save zr-tex8r/4419089 to your computer and use it in GitHub Desktop.
LaTeX: Using TeX as a calculator
\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