6

I am new to latex, I am trying to include output of TI84 calculator in my document.

It is supposed to look like this:

actual TI 84

Following is what I am able to make.

my texas calculator

My output's height and width arrange itself, I want fixed height/width, with custom padding and text wrapping around inside the box. Any help will be greatly appreciated.

My code is

{\scriptsize
\setmainfont{Texas Instruments TI-84 series}
\tabulinesep=0.05 in
\begin{tabu} to 1 in {|c |}
\hline
normalcdf(-1.5,2)\\
\hfill .9104427093
\\\hline
\end{tabu}
}
2

3 Answers 3

3

The \vbox to... primitive construction is the answer to your question. You can try the following code:

\def\tifont{\setmainfont{Texas Instruments TI-84 series}}
\setbox0=\hbox{\tifont 12345678901234567\kern2pt}\edef\tiwidth{\wd0}
\def\ticalc#1{\hbox{\vrule\vbox to2cm{\hrule\kern1pt
   \def\l##1|{\hbox to\tiwidth{\kern1pt##1\kern1pt\hss}}\tifont #1\vss\hrule}\vrule}}

\ticalc{
\l normalcdf(-1.5,2)|
\l\hfill .9104427093|
}

Edit: My second version of the macro \ticalc implements the auto-wrapping. The width of the box has to be set by setbox. See the line with \setbox0 where 16 characters is supposed. The text with more length than this dimension is wrapped. The wrapping is possible between each pair of characters.

The optional \result followed by text can be included in the parameter of the \ticalc macro. Such text is printed at next line aligned to right.

\def\titext{\hsize=\tiwidth \leftskip=1pt\rightskip=1pt plus1fil \tifont \noindent \titextA}
\def\titextA{\futurelet\next\titextB}
\def\titextB{\ifx\next\result \else \null\next \penalty0 \expandafter\titextC \fi}
\def\titextC{\afterassignment\titextA \let\next= }

\newfontfamily\tifont{Texas Instruments TI-84 series}
\setbox0=\hbox{\tifont 1234567890123456\kern2pt}\edef\tiwidth{\wd0}
\def\ticalc#1{\hbox{\vrule\vbox to2cm{\hrule\kern1pt\titext#1\result\relax\vss\hrule}\vrule}}
\def\result#1\relax{\par\let\result=\relax \hbox to\tiwidth{\hss#1\kern1pt}}

\ticalc{normalcdf(-1.5,2)\result .9104427093}

\ticalc{abcdefghijklmnopqrsyuyu}
5
  • @VarunSeth Do you mean wrapping between letters inside words?
    – wipet
    Dec 13, 2014 at 7:03
  • \newfontfamily\tifont{Texas Instruments TI-84 series} is better than resetting the main font.
    – egreg
    Dec 13, 2014 at 15:57
  • @egreg Thanks, I've added the code by your advice. I put my original line blind, because I have no such font and I didn't load the font package used by OP, because it is LaTeX specific package.
    – wipet
    Dec 13, 2014 at 16:21
  • It would be nice to have packages indicated that are necessary to get this example to compile.
    – A.Ellett
    Dec 13, 2014 at 16:57
  • @A.Ellett Sorry, I can't serve, because I don't know what packages were used by OP. I guess that it is some from LaTeX and that XeTeX or LuaTeX were used, but I don't know. Anyway, the example cannot be compilable if the special font isn't present. I hope that if somebody needs to try this example then he/she is able to think and he/she does \let\tifont=\tt for example.
    – wipet
    Dec 13, 2014 at 18:47
6

The following solution borrows some code from this great answer of egreg:

\ExplSyntaxOn
\NewEnviron{terminal}
 {
  \raggedright\varun_zerohyphen:V \BODY
 }

\seq_new:N \l_varun_body_seq

\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 \penalty0 \scan_stop: }
  \c_space_tl
 }
\ExplSyntaxOff

This defines a new environment terminal that automatically wraps the text inside the box.

The box is made through a minipage inside a tcolorbox environment.

This is the full code

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{amssymb}

\usepackage{fontspec}
\newfontfamily\TIfont{Texas Instruments TI-84 series}

% Start ----------- Code from https://tex.stackexchange.com/a/153692

\usepackage{xparse,environ}

\ExplSyntaxOn
\NewEnviron{terminal}
 {
  \raggedright\varun_zerohyphen:V \BODY
 }

\seq_new:N \l_varun_body_seq

\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 \penalty0 \scan_stop: }
  \c_space_tl
 }
\ExplSyntaxOff

% End ----------- Code from https://tex.stackexchange.com/a/153692


\begin{document}

{\scriptsize
\TIfont
\begin{tcolorbox}[%
      arc=0pt,
      outer arc=0pt,
      boxsep=1pt,
      top=0mm,
      bottom=10mm,
      left=0mm,
      right=0mm,
      boxrule=0.3pt,
      colback=white,
      colframe=black,
      hbox
]
\begin{minipage}{1.14in}
\begin{terminal}
normalcdf(-1.5,2)\par
\hfill .9104427093\par
$\blacksquare$\par
\end{terminal}
\end{minipage}
\end{tcolorbox}
}

\end{document} 

and this is the result:

enter image description here

1
  • 1
    I wouldn't reset the main font, but rather define a new font family: add \newfontfamily\TI{...} to the preamble and issue \TI in the code for terminal.
    – egreg
    Dec 13, 2014 at 16:01
4

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.

enter image description here

4
  • Why the use of \c_space_tl in the definition of \varun_printword:n? Things seem to work with or without it.
    – A.Ellett
    Dec 13, 2014 at 20:43
  • @A.Ellett Probably it was necessary for the application made in tex.stackexchange.com/a/153692/27635 If it ain't broken, don't fix it!
    – egreg
    Dec 13, 2014 at 20:59
  • Thanks for pointing to that example. I am now quite enlightened. :)
    – A.Ellett
    Dec 13, 2014 at 21:05
  • +1 for the customizable environment. P.S. I couldn't upvote the answer where I borrowed your code because I did it already time ago ;-) Dec 14, 2014 at 5:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .