2

First: This is a a question similar to the one here.

How do I write a fraction as output in the green box?

The fraction should appear just after the 2 and by similar to the output from \frac{3}{5} but pixilated, both in the displayed indput (green screen, left) and the displayed output (green screen, right).

Preferable but not necessary: The height of the nominator should be 5 pixels, then 1 pixels blank space, then 1 horizontal line as the stroke, then 1 pixels blank space, and then the height of the denominator should be 5 pixels. Also, the fraction should be vertically centered relative to the number before the fraction.

output

\documentclass[
  a4paper,
  11pt
]{article}

\usepackage[varg]{newpxmath}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}

\usepackage[most]{tcolorbox}
  \colorlet{blackened}{black!90!white}
  \colorlet{blackish}{black!70!white}
  \colorlet{greyish}{black!60!white}
  \colorlet{lightgreyish}{black!10!white}
  \colorlet{whiteish}{white}
  \colorlet{orangeish}{yellow!90!red}
  \colorlet{greenish}{green!16!gray}
  \colorlet{redish}{red!80!black}

\tcbset{
  calbackground/.style = {
    enhanced,
    leftright skip = 0.15cm,
    beforeafter skip = 0pt,
    toptitle = 0mm,
    bottomtitle = 0mm,
    right = 3pt,
    left = 3pt,
    top = 3pt,
    bottom = 3pt,
    boxsep = 0pt,
    boxrule = 0mm,
    sharp corners,
    sidebyside,
    sidebyside gap = 6pt,
    lefthand ratio = 0.622,
    bicolor,
    colback = lightgreyish,
    colbacklower = greenish,
    colframe = white,
    autoparskip,
  }
}

\newtcbtheorem[no counter]{calx}{Calculator}{calbackground}{cax}

\newtcbox{\KY}[1][]{
  enhanced,
  on line,
  arc = 2pt,
  outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = orangeish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\newtcbox{\KYm}[1][]{
    enhanced,
    on line,
    arc = 2pt,
    outer arc = 2pt,
    boxrule = 0pt,
    bottomrule = 0.25mm,
    rightrule = 0.2mm,
    boxsep = 0pt,
    left = 0pt,
    right = 0 pt,
    top = 1pt,
    bottom = 1pt,
    interior style = {
      top color = blackish,
      bottom color = blackened
    },
    colframe = greyish,
    width = 2.5em,
    tcbox width = forced center,
    equal height group = K,
    valign = center,
    fontupper = \footnotesize\sffamily,
    coltext = orangeish,
    before upper = \vrule width 0pt height 2ex depth 1ex\relax$,
    after upper = $,
    }

\newtcbox{\KN}{
  enhanced,
  on line,
  arc = 2pt, outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = whiteish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\usepackage{lcd}
  \LCDcolors{black}{greenish}
  \DefineLCDchar{sq}{11100001000100011100000000000000000}
  \DefineLCDchar{tm}{00000100010101000100010101000100000}
  \DefineLCDchar{dv}{00000001000000011111000000010000000}
  \DefineLCDchar{mu}{00011000011110100001000000000000000}
  \DefineLCDchar{sc}{11011010011001000000000000000000000}

\DeclareMathOperator{\ee}{\textrm{e}}

\usepackage{MnSymbol}
\usepackage{xfrac}

\begin{document}

\begin{calx}{}{}
  \KY{2nd}
  \KYm{\frac{\mathrm{n}}{\mathrm{d}}}
  \KN{2}
  \KYm{\smalltriangleright}
  \KN{3}
  \KYm{\smalltriangleright}
  \KN{5}
  \KYm{\smalltriangleright}
  \KY{enter}
  \tcblower
  {\Large
   \vspace*{-0.5ex}
   \textLCD[0]{19}|2|
   \textLCD[0]{18}|                 2|}
\end{calx}

\end{document}
  • I can manage a pixelated fraction in the green box, but it takes the full vertical height of both rows. I take it that is not what you want. – Steven B. Segletes Jun 21 '18 at 14:36
  • @StevenB.Segletes Yes, that is not what I want, unfortunately. – Svend Tveskæg Jun 21 '18 at 14:43
3

Not sure I really understand the way the \textLCD macro works, but using a very manual approach of (what else) stacking, I was able to do (hopefully) something like what is desired.

REVISED SOLUTION

I originally had \pixelfrac{NUMERATOR}{DENOMINATOR} which could create the fraction, but I still had to use stacks to overlay it over the other content of the line. Now, I discovered I am able to insert a macro (without argument) inline into \textLCD. To make use of this, however, I have to invoke \pixelfrac (which takes arguments) prior to \textLCD and have it save the contents of the \pixelfrac into a macro without an argument. I can then use that macro-without-argument in the argument of \textLCD.

Then I discovered that my need to use a zero-width \pixelfrac had implications on the horizontal spacing of the \textLCD. I therefore had to add an additional argument to \pixelfrac in the form of

\pixelfrac{NUMERATOR}{DENOMINATOR}{EVENTUAL COLUMN PLACEMENT}

so that \pixelfrac could pad the box with the right amount of space to make it appear in the needed location.

So, in the MWE below, the guts of the pixelated construction is:

   \pixelfrac{3}{5}{2}%
   \pixelfrac[\thefracB]{1}{5}{18}%
   \textLCD[0]{18}|2\thefrac*|
   \textLCD[0]{18}|                5\thefracB|}

which indicates that the default macro \thefrac should place the fraction 3/5 into column 2 and \thefracB should place 1/5 into column 18.

The MWE:

\documentclass[
  a4paper,
  11pt
]{article}

\usepackage[varg]{newpxmath}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}

\usepackage[most]{tcolorbox}
  \colorlet{blackened}{black!90!white}
  \colorlet{blackish}{black!70!white}
  \colorlet{greyish}{black!60!white}
  \colorlet{lightgreyish}{black!10!white}
  \colorlet{whiteish}{white}
  \colorlet{orangeish}{yellow!90!red}
  \colorlet{greenish}{green!16!gray}
  \colorlet{redish}{red!80!black}

\tcbset{
  calbackground/.style = {
    enhanced,
    leftright skip = 0.15cm,
    beforeafter skip = 0pt,
    toptitle = 0mm,
    bottomtitle = 0mm,
    right = 3pt,
    left = 3pt,
    top = 3pt,
    bottom = 3pt,
    boxsep = 0pt,
    boxrule = 0mm,
    sharp corners,
    sidebyside,
    sidebyside gap = 6pt,
    lefthand ratio = 0.622,
    bicolor,
    colback = lightgreyish,
    colbacklower = greenish,
    colframe = white,
    autoparskip,
  }
}

\newtcbtheorem[no counter]{calx}{Calculator}{calbackground}{cax}

\newtcbox{\KY}[1][]{
  enhanced,
  on line,
  arc = 2pt,
  outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = orangeish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\newtcbox{\KYm}[1][]{
    enhanced,
    on line,
    arc = 2pt,
    outer arc = 2pt,
    boxrule = 0pt,
    bottomrule = 0.25mm,
    rightrule = 0.2mm,
    boxsep = 0pt,
    left = 0pt,
    right = 0 pt,
    top = 1pt,
    bottom = 1pt,
    interior style = {
      top color = blackish,
      bottom color = blackened
    },
    colframe = greyish,
    width = 2.5em,
    tcbox width = forced center,
    equal height group = K,
    valign = center,
    fontupper = \footnotesize\sffamily,
    coltext = orangeish,
    before upper = \vrule width 0pt height 2ex depth 1ex\relax$,
    after upper = $,
    }

\newtcbox{\KN}{
  enhanced,
  on line,
  arc = 2pt, outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = whiteish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\usepackage{lcd}
  \LCDcolors{black}{greenish}
  \DefineLCDchar{sq}{11100001000100011100000000000000000}
  \DefineLCDchar{tm}{00000100010101000100010101000100000}
  \DefineLCDchar{dv}{00000001000000011111000000010000000}
  \DefineLCDchar{mu}{00011000011110100001000000000000000}
  \DefineLCDchar{sc}{11011010011001000000000000000000000}

\DeclareMathOperator{\ee}{\textrm{e}}

\newlength\cwidth
\Large\cwidth=.61em\relax\normalsize
\newlength\coffset
\Large\coffset=.3em\relax\normalsize

\usepackage{MnSymbol}
\usepackage{xfrac}
\usepackage{stackengine}
% \pixelfrac{NUMERATOR}{DENOMINATOR}{EVENTUAL COLUMN PLACEMENT}
\newcommand\pixelfrac[4][\thefrac]{%
  \setbox0=\hbox{\tiny\textLCD[0]{0}|#2|}%
  \setbox2=\hbox{\tiny\textLCD[0]{0}|-|}%
  \setbox4=\hbox{\tiny\textLCD[0]{0}|#3|}%
% \scriptsize GETS CLIPPED...MUST USE \tiny
%  \setbox0=\hbox{\scriptsize\textLCD[0]{0}|#2|}%
%  \setbox2=\hbox{\scriptsize\textLCD[0]{0}|-|}%
%  \setbox4=\hbox{\scriptsize\textLCD[0]{0}|#3|}%
  \savestack#1{\kern-\coffset\kern#4\cwidth\smash{\raisebox{6pt}{\stackunder[-9pt]{\copy2}{\stackon[2pt]{\copy4}{\copy0}}}}\kern-#4\cwidth\kern\coffset}%
}
\begin{document}

\begin{calx}{}{}
  \KY{2nd}
  \KYm{\frac{\mathrm{n}}{\mathrm{d}}}
  \KN{2}
  \KYm{\smalltriangleright}
  \KN{3}
  \KYm{\smalltriangleright}
  \KN{5}
  \KYm{\smalltriangleright}
  \KY{enter}
  \tcblower
  {\Large
   \vspace*{-0.5ex} 
   \pixelfrac{3}{5}{2}%
   \pixelfrac[\thefracB]{1}{5}{18}%
   \textLCD[0]{18}|2\thefrac*|
   \textLCD[0]{18}|                5\thefracB|}
\end{calx}

\end{document}

enter image description here

ORIGINAL CODE

\documentclass[
  a4paper,
  11pt
]{article}

\usepackage[varg]{newpxmath}
\usepackage[
  hmargin = 2.4cm,
  vmargin = 3cm
]{geometry}

\usepackage[most]{tcolorbox}
  \colorlet{blackened}{black!90!white}
  \colorlet{blackish}{black!70!white}
  \colorlet{greyish}{black!60!white}
  \colorlet{lightgreyish}{black!10!white}
  \colorlet{whiteish}{white}
  \colorlet{orangeish}{yellow!90!red}
  \colorlet{greenish}{green!16!gray}
  \colorlet{redish}{red!80!black}

\tcbset{
  calbackground/.style = {
    enhanced,
    leftright skip = 0.15cm,
    beforeafter skip = 0pt,
    toptitle = 0mm,
    bottomtitle = 0mm,
    right = 3pt,
    left = 3pt,
    top = 3pt,
    bottom = 3pt,
    boxsep = 0pt,
    boxrule = 0mm,
    sharp corners,
    sidebyside,
    sidebyside gap = 6pt,
    lefthand ratio = 0.622,
    bicolor,
    colback = lightgreyish,
    colbacklower = greenish,
    colframe = white,
    autoparskip,
  }
}

\newtcbtheorem[no counter]{calx}{Calculator}{calbackground}{cax}

\newtcbox{\KY}[1][]{
  enhanced,
  on line,
  arc = 2pt,
  outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = orangeish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\newtcbox{\KYm}[1][]{
    enhanced,
    on line,
    arc = 2pt,
    outer arc = 2pt,
    boxrule = 0pt,
    bottomrule = 0.25mm,
    rightrule = 0.2mm,
    boxsep = 0pt,
    left = 0pt,
    right = 0 pt,
    top = 1pt,
    bottom = 1pt,
    interior style = {
      top color = blackish,
      bottom color = blackened
    },
    colframe = greyish,
    width = 2.5em,
    tcbox width = forced center,
    equal height group = K,
    valign = center,
    fontupper = \footnotesize\sffamily,
    coltext = orangeish,
    before upper = \vrule width 0pt height 2ex depth 1ex\relax$,
    after upper = $,
    }

\newtcbox{\KN}{
  enhanced,
  on line,
  arc = 2pt, outer arc = 2pt,
  boxrule = 0pt,
  bottomrule = 0.15mm,
  rightrule = 0.2mm,
  boxsep = 0pt,
  left = 0pt,
  right = 0pt,
  top = 1pt,
  bottom = 1pt,
  interior style = {
    top color = blackish,
    bottom color = blackened
  },
  colframe = greyish,
  width = 2.5em,
  tcbox width = forced center,
  equal height group = K,
  valign = center,
  fontupper = \footnotesize\sffamily,
  coltext = whiteish,
  before upper = \vrule width 0pt height 2ex depth 1ex\relax,
}

\usepackage{lcd}
  \LCDcolors{black}{greenish}
  \DefineLCDchar{sq}{11100001000100011100000000000000000}
  \DefineLCDchar{tm}{00000100010101000100010101000100000}
  \DefineLCDchar{dv}{00000001000000011111000000010000000}
  \DefineLCDchar{mu}{00011000011110100001000000000000000}
  \DefineLCDchar{sc}{11011010011001000000000000000000000}

\DeclareMathOperator{\ee}{\textrm{e}}

\usepackage{MnSymbol}
\usepackage{xfrac}
\usepackage{stackengine}
\newcommand\pixelfrac[2]{%
  \setbox0=\hbox{\scriptsize\textLCD[0]{0}|#1|}%
  \setbox2=\hbox{\scriptsize\textLCD[0]{0}|-|}%
  \setbox4=\hbox{\scriptsize\textLCD[0]{0}|#2|}%
  \stackunder[-12pt]{\copy2}{\stackon[3pt]{\copy4}{\copy0}}%
}
\begin{document}

\begin{calx}{}{}
  \KY{2nd}
  \KYm{\frac{\mathrm{n}}{\mathrm{d}}}
  \KN{2}
  \KYm{\smalltriangleright}
  \KN{3}
  \KYm{\smalltriangleright}
  \KN{5}
  \KYm{\smalltriangleright}
  \KY{enter}
  \tcblower
  {\Large
   \vspace*{-0.5ex} 
   \setbox6=\hbox{\kern-1pt\textLCD[]{18}|2 +|}
   \stackengine{2pt}{\copy6}{\pixelfrac{3}{5}\kern9.55em}{O}{c}{F}{F}{L}
   \textLCD[0]{18}|                 2|}
\end{calx}

\end{document}

enter image description here

  • This looks really good. There are a few things that I would like to have improved upon: (1) No space around the fraction and (2) can it be made into a macro so that I can use, say, \pixelfrac{3}{5}. – Svend Tveskæg Jun 21 '18 at 15:32
  • 1
    @SvendTveskæg I have automated that part which creates the fraction, but because \textLCD is verbatim, I don't know how to insert it inline the argument, and still have to manually overlay it atop the remainder of the line. But I will keep playing. – Steven B. Segletes Jun 21 '18 at 15:52
  • @SvendTveskæg Please see my revision. – Steven B. Segletes Jun 21 '18 at 16:50
  • 1
    @SvendTveskæg In my revised code, you see some \scriptsize lines commented out, and \tiny lines left intact. You can reverse the commenting and see for yourself what happens. Things get vertically clipped also extend out of the green box. What would be needed to fix (and I don't know how to do it), would be to make the default line spacing more inside the green box, to allow the fraction more breathing room. – Steven B. Segletes Jun 21 '18 at 17:30
  • 1
    @SvendTveskæg Argh. One could easily add the - or -- as an additional argument (ugly), or one could send the numerator and denominator to a macro to count digits, harder to do, but less ugly. The problem then, is that I use the dash to create the vinculum, and multiple dashes such as --- for a 3 digit entry leaves a gap between each dash. I don't know how to fix that. Also, the \textLCD macro wants to left-align things inside of a stack, and so that is an added issue, if the numerator and denominator have different digit counts. – Steven B. Segletes Jun 21 '18 at 18:37

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.