A variant of karlkoeller's answer, where the width, height, padding and alignment of the box are customizable. Alignment refers to the vertical alignment of the box with respect to the surrounding material.
The setup expects a monospaced font is used in the box; I used “DejaVu Sans Mono” as I don't have the “Texas Instruments TI-84 series” font; just change the font in the \newfontfamily
line.
Default values:
- height: 8 (lines)
- width: 16 (characters)
- padding: 1pt
- align: c
Possible values for align
are c
, t
and b
.
You can set the values with a key-value interface in the optional argument to terminal
as shown.
\documentclass{article}
\usepackage{amssymb}
\usepackage{xparse,environ}
\usepackage{fontspec}
\newfontfamily\TI{DejaVu Sans Mono} % or whatever
\ExplSyntaxOn
\NewEnviron{terminal}[1][]
{
\scriptsize\TI
\keys_set:nn { varun/display } { width=16 , #1 }
\fbox
{
\parbox
[\l_varun_align_tl] % outer alignment
[\l_varun_height_int \baselineskip] % height
[t] % inner alignment
{\l_varun_width_dim} % width
{
\raggedright % don't try filling up lines
\varun_zerohyphen:V \BODY
}
}
}
\seq_new:N \l_varun_body_seq
\dim_new:N \l_varun_width_dim
\cs_new_protected:Npn \varun_zerohyphen:n #1
{
\seq_set_split:Nnn \l_varun_body_seq { ~ } { #1 }
\seq_map_inline:Nn \l_varun_body_seq { \varun_printword:n { ##1 } }
}
\cs_generate_variant:Nn \varun_zerohyphen:n { V }
\cs_new_protected:Npn \varun_printword:n #1
{
\tl_map_inline:nn { #1 } { ##1 \penalty\c_zero }
\c_space_tl
}
\cs_new_protected:Npn \__varun_set_width:n #1
{
\hbox_set:Nn \l_tmpa_box { \prg_replicate:nn { #1 } { A } }
\dim_set_eq:NN \l_varun_width_dim \box_wd:N \l_tmpa_box
}
\keys_define:nn { varun/display }
{
width .code:n = \__varun_set_width:n { #1 },
padding .code:n = \dim_set:Nn \fboxsep { #1 },
padding .initial:n = 1pt,
height .int_set:N = \l_varun_height_int,
height .initial:n = 8,
align .tl_set:N = \l_varun_align_tl,
align .initial:n = c,
}
\ExplSyntaxOff
\begin{document}
\begin{terminal}
normalcdf(-1.5,2)\\
\hfill .9104427093\\
1\\
2\\
3\\
4\\
▪
\end{terminal}\qquad
\begin{terminal}[width=20]
normalcdf(-1.5,2)\\
\hfill .9104427093\\
▪
\end{terminal}
\bigskip
\begin{terminal}[align=t]
normalcdf(-1.5,2)\\
\hfill .9104427093\\
▪
\end{terminal}\qquad
\begin{terminal}[align=t,height=4]
normalcdf(-1.5,2)\\
\hfill .9104427093\\
▪
\end{terminal}\qquad
\begin{terminal}[align=t,height=4,padding=6pt]
normalcdf(-1.5,2)\\
\hfill .9104427093\\
▪
\end{terminal}
\end{document}
Instead of \fbox
one could use the fancier methods provided by tcolorbox
.