How to transcript codes from HP 50G in LaTeX

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}

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.