7

I have a code from HP 48/50G series, as shown in the image below.

enter image description here

The closest that I did, using [lstlisting] is shown in the code snippet below.

\begin{lstlisting}
<< SWAP DUP SIZE 
HEAD 1 - -> J vec N
<< 0 N FOR k vec k 1 
+ GET i NEG 2 * pi *
k * J * N 1 + / EXP 
* NEXT N 1 + -> LIST sum LIST
>> >>
\end{lstlisting}

enter image description here

Is there any way to improve it to be the same as HP screenshot?

  • 1
    Can you make your snippet into a fully compilable MWE please? – Thruston Oct 4 '17 at 19:00
  • You want to set it in a monospace font: something like \lstset{basicstyle=\small\ttfamily} – Thruston Oct 4 '17 at 19:03
  • For me, the problem are simbols like "sum", "pi" and "->" How to improve it? imagine that someone wishing to reproduce the same sequence in the calculator's programming can not find these symbols.This person would have to imagine what these mean and substitute for the appropriate equivalent. Does not work. These need to be exactly the same. – cbe-user-99263 Oct 5 '17 at 13:20
  • @cbe-user-99263 Also << and >>? – Manuel Oct 5 '17 at 14:38
  • Yes, additional simbols "<<" and ">>" are also desirable. If possible, you are also welcome. I think the best of all would be to load fonts set that contained all the symbols used in HP. I do not know if there are any free caracters font of this type. – cbe-user-99263 Oct 5 '17 at 15:25
11

Does this look better?

\documentclass[a4paper]{article}
\usepackage{listings}
\lstset{basicstyle=\ttfamily, columns=fullflexible, keepspaces=true}
\begin{document}
\begin{lstlisting}
<< SWAP DUP SIZE 
HEAD 1 - -> J vec N
<< 0 N FOR k vec k 1 
+ GET i NEG 2 * pi *
k * J * N 1 + / EXP 
* NEXT N 1 + -> LIST sum LIST
>> >>
\end{lstlisting}
\end{document}

enter image description here

The manual for listings is here.

Appendix J of the HP50G manual shows HP's suggestions for representing the upper half of the HP50G character set in plain 7-bit ASCII codes, but if you want to show them in LaTeX it's not too hard to type them in UTF-8.

But if you do this you will need to find a ttfamily font with support for all the characters you need. And you will need to use an engine that can cope with Unicode directly. Here is a version using TeX Gyre Cursor and xelatex:

\documentclass[a4paper]{article}
\usepackage{fontspec}
\setmonofont{TeX Gyre Cursor}
\usepackage{listings}
\lstset{basicstyle=\ttfamily, columns=fullflexible, keepspaces=true}
\begin{document}
\begin{lstlisting}
« SWAP DUP SIZE 
HEAD 1 - → J vec N
« 0 N FOR k vec k 1 
+ GET i NEG 2 * π *
k * J * N 1 + / EXP 
* NEXT N 1 + →LIST 
∑LIST » »
\end{lstlisting}
\end{document}

which produces this:

enter image description here

On the Mac I can use the keyboard viewer to find the key combinations for the Greek characters, and the right arrow and angle bracket characters can be found in the "Emoji and Symbols viewer" tool. I'm sure there are similar mechanisms for other platforms.

I think you can also use the "literate programming" features of listings to get some of these special characters automagically, but I've never got that far in the manual.

|improve this answer|||||
  • Thanks for your help, but "sum", "pi" and "->" still the same. – cbe-user-99263 Oct 5 '17 at 13:24
  • 1
    Some fonts are available here educalc.net/2336507.page maybe helps with XeLaTeX? – percusse Oct 5 '17 at 16:19
  • Using overleaf it works overleaf.com/read/csfwwftrdscy But using TeXStudio no: Undefined control sequence. ...\c_e_fp { 2.718 2818 2845 9045 } – cbe-user-99263 Oct 5 '17 at 19:38
  • Someone did not understand my question and gave me -1. The question was not the form of the letter but the symbols used. @Thruston answered very well. – cbe-user-99263 Oct 5 '17 at 19:44
15

This answer tries to reproduce the screenshot. It uses the lcd package, which defines an extended alphanumeric character set, with each character constructed using dots set in a 5 x 7 matrix. Thus, characters are defined by a binary sequence of 35 bits to signify whether a cell has a visible dot, or is empty.

The screen shot shows two character sizes, with the top two rows smaller than the code that follows. The bottom row puts white text on a black background. These three rows are created using the \textLCD macro, written as:

\textLCD[LCDcorr]{LCDcolumns}⟨delimchar⟩LCDtext ⟨delimchar⟩

where LCDcorr is a correction for the offset relative to adjacent text, LCDcolumns is the number of display columns, delimchar is a character chosen to delimit the beginning and end of the LCDtext.

The script is set using the \LCD macro, written as:

\LCD{LCDlines}{LCDcolumns}⟨delimchar⟩LCDtext ⟨delimchar⟩ ⟨delimchar⟩LCDtext ⟨delimchar⟩

where LCDlines is the number of lines in the block.

Row 1 of the screen uses quotation marks. The opening quote had to be redefined using \DefineLCDchar to match it with the closing quote.

The lcd package creates predefined special characters such as pi and right arrow, which are written enclosed in {} e.g. {pi}. Curly brackets, which surround HOME in row 2, have to be reassigned to another character and defined using \DefineLCDchar to be able to use them in row 2. I chose to redefine ( and ), which were not required anywhere in the script. << and >> are also redefined since they are 5 pixels high whereas <> occupy the full 7 pixel height. << and >> are assigned to ^ and ;, respectively.

Use of both \textLCD and \LCD resulted in a slightly ragged right edge. I hid the raggedness by placing the code in a tcolorbox, with colback set to the same color as the screen display. The MWE still shows the closest syntax I could find to produce left and right edges that were completely aligned, although those settings are made redundant by using the tcolorbox.

Two examples are provided. The first is what's possible "out of the box" with the lcd package. In response to ShreevatsaR's comment, it is also possible to tighten up the pixels so that they are adjoined. This was done by changing \line(1,0){0.7} to \line(1,0){1.0} for the horizontal spacing and \linethickness{0.7\unitlength} to \linethickness{1.0\unitlength} for the vertical spacing.

enter image description here

This is the MWE:

\documentclass[a4paper]{article}
\usepackage[latin1]{inputenc}
\usepackage{lcd}
\usepackage{xcolor}
\usepackage[most]{tcolorbox}
\setlength\parindent{0.25pt}

% define the color of the display
\definecolor{background}{RGB}{185,202,187}
\tcbset{colframe=white,colback=background,sharp corners,left=0pt,right=0pt,top=0pt,bottom=0pt,width=7.4cm}

% redefine left quote
\DefineLCDchar{`}{01100010000010000000000000000000000} 
% make left curly bracket and use (, which is not required elsewhere
\DefineLCDchar{(}{00111010000100010000010000100000111} 
% make right curly bracket and use ), which is not required elsewhere
\DefineLCDchar{)}{11100000100001000001000100001011100} 
% make left <<
\DefineLCDchar{^}{00000001010101010100010100010100000}
% make right >>
\DefineLCDchar{;}{00000101000101000101010101010000000}

\setlength\LCDunitlength{0.5mm}

\begin{document}
\LCDnoframe
\LCDcolors{black}{background}

\textbf{Example 1}

\begin{tcolorbox}
\textLCD[-1]{33} |RAD R&Z HEX C= `X'|           \\[-2pt] % need redefined ` to match '
\textLCD{33}     |(HOME)|                       \\[-1pt] % () are written as curly
\LCD{8}{23}      |-----------------------|      \\[-1pt]              
                 |1: ^ SWAP DUP SIZE| 
                 |   HEAD 1 - {rarrow} J vec N|
                 |   ^ 0 N FOR k vec k 1| 
                 |   + GET i NEG 2 * {pi} *|
                 |   k * J * N 1 + {/} EXP| 
                 |   * NEXT N 1 + {rarrow}LIST|
                 |   {Sigma}LIST ; ;|         \\[-4pt]
\LCDcolors{white}{black}
\textLCD{33}    +GO1A|IOPAR|DFT4| DFT3| DFT2| DFT1+  % change the text delimiter to +
\end{tcolorbox}

% To reduce the pixelation, reduce the x,y spacing of the pixels

\makeatletter
\renewcommand*\@DrawLCDDot{%
    \put(\the\c@@LCDdotx,\the\c@@LCDdoty.35){\line(1,0){1.0}}} % was \line(1,0){0.7}
\makeatother
\makeatletter
\renewcommand*\@LCDstart{\unitlength\LCDunitlength
    \begin{picture}(\the\@tempcntb.7,\the\@tempcnta.7)(0,\the\c@@LCDlower)
    \color{\@LCDfr}
    \if@textLCD\advance\@tempcnta 2\fi
    \put(0,0){\fboxsep\z@\colorbox{\@LCDbg}{\@LCDbox(\the\@tempcntb.7,\the\@tempcnta.7){}}}
    \color{\@LCDfg}
    \linethickness{1.0\unitlength}} % was 0.7\unitlength
\makeatother

\bigskip

\textbf{Example 2}

\begin{tcolorbox}
    \textLCD[-1]{33} |RAD R&Z HEX C= `X'|           \\[-2pt] % need redefined ` to match '
    \textLCD{33}     |(HOME)|                       \\[-1pt] % () are written as curly
    \LCD{8}{23}      |-----------------------|      \\[-1pt]              
    |1: ^ SWAP DUP SIZE|                                     % use ^ for <<
    |   HEAD 1 - {rarrow} J vec N|
    |   ^ 0 N FOR k vec k 1| 
    |   + GET i NEG 2 * {pi} *|
    |   k * J * N 1 + {/} EXP| 
    |   * NEXT N 1 + {rarrow}LIST|
    |   {Sigma}LIST ; ;|         \\[-4pt]                    % use ; for >>
    \LCDcolors{white}{black}
    \textLCD{33}    +GO1A|IOPAR|DFT4| DFT3| DFT2| DFT1+  % change the text delimiter to +
\end{tcolorbox}

\end{document}
|improve this answer|||||
  • 1
    Very cool, is it possible to make the adjacent pixels touch? That would match the screenshot even more closely. This looks more pixelated the image in the question, even though both are using roughly the same resolution (number of pixels that each character occupies), because of the empty space around each pixel. – ShreevatsaR Oct 7 '17 at 1:13
  • 1
    An impressive answer. Congratulations! I didn't imagine this was possible using LaTex. – cbe-user-99263 Oct 7 '17 at 10:34
  • 1
    About "»" character. Is it possible to use it with \usepackage{lcd} instead of ">>" ? – cbe-user-99263 Oct 7 '17 at 19:02
  • 1
    @ShreevatsaR Yes, it is possible to reduce the pixelation. I added an example. – Ross Oct 8 '17 at 5:08
  • @cbe-user-99263 I defined characters for << and >> to correctly match the LCD pixels. – Ross Oct 8 '17 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for?Browse other questions tagged or ask your own question.