科学计算器的小显示屏

科学计算器的小显示屏

从...开始液晶显示屏文档包(一页),特别关注这个问题,其中有@Thomas F. Sturm这里):,

\documentclass[openany,10pt]{book}

\usepackage{newpxtext}

\usepackage[varg]{newpxmath} %font package

\usepackage[letterpaper,margin=0.75in,bindingoffset=0.5in]{geometry}

\usepackage[most]{tcolorbox}
    \colorlet{blackened}{black!90!white}
    \colorlet{blackish}{black!70!white}
    \colorlet{greyish}{black!60!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.25cm,beforeafter skip=0pt,
    toptitle=0mm,bottomtitle=0mm,
    right=2mm,left=2mm,
    top=1pt,
    bottom=0.25cm,
    boxsep=0pt,
    boxrule=0mm,
    sharp corners,
    sidebyside,
    sidebyside gap=2mm,
    lefthand ratio=0.6,
    bicolor,
    colback=black!10!white,
    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.25mm,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=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$,
    after upper=$,
    }

\newtcbox{\KN}{
    enhanced,
    on line,
    arc=2pt,outer arc=2pt,
    boxrule=0pt,bottomrule=0.25mm,rightrule=0.2mm,
    boxsep=0pt,left=0pt,right=0pt,top=1pt,bottom=1pt,
    interior style={top color=blackish,bottom color=blackened},
    colframe=greyish,
    width=1.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} %boxes
\usepackage{xfrac} %sfrac
\usepackage{lipsum} %for textwidth comparison
    \setlipsumdefault{1-2}

\begin{document}

\begin{calx}{}{}
\KY{$($}\KN{3}\KY{$x^2$}\KN{-}\KN{4}\KY{$x^2$}\KN{-}\KN{6}\KY{$x^2$}\KY{$)$}\KN{$=$}
\tcblower
{\Large\textLCD[0]{20}|(3{sq}-4{sq}-6{sq})|}
{\LARGE\textLCD[0]{16}|             -43|}
\end{calx}
%
\begin{calx}{}{}
\KN{$\div$}\KY{$($}\KY{$(-)$}\KN{2}\KN{$\times$}\KN{4}\KN{$\times$}\KN{6}\KY{$)$}\KN{$=$}
\tcblower
{\Large\textLCD[0]{20}|ANS{dv}(-2{tm}4{tm}6)|}
{\LARGE\textLCD[0]{16}|    0.8958333333|}
\end{calx}
%
\begin{calx}{}{}
\KY{$\cos^{-1}$}\KY{ANS}\KN{$=$}
\tcblower
{\Large\textLCD[0]{20}|cos{mu}(ANS|}
{\LARGE\textLCD[0]{16}|     26.38432975|}
\end{calx}
%
\begin{calx}{}{}
\KY{$\circ\,\prime\,\prime\prime$}
\tcblower
{\Large\textLCD[0]{20}|cos{mu}(ANS|}
{\LARGE\textLCD[0]{16}|     26°23'3.59{sc} |}
\end{calx}

\lipsum

\KYm{x^2}%
\KYm{x^3}%
\KYm{x^{-1}}%
\KYm{x^{\filledsquare}}%
\KYm{\sqrt{\filledmedsquare}}%
\KYm{\sqrt[3]{\filledmedsquare}}%
\KYm{\sqrt[\filledsquare]{\medsquare}}\\

\KY{$\ln$}%
\KY{$\log$}%
\KY{$\log_{\filledsquare}\medsquare$}%
\KY{$10^{\filledsquare}$}%
\KY{$\ee^{\filledsquare}$}\\

\KY{$(-)$}%
\KY{$\frac{\filledmedsquare}{\medsquare}$}%
\KY{$\sfrac{\filledmedsquare}{\medsquare}$}%
\KY{$\tfrac{\filledmedsquare}{\medsquare}$}\\

\KY{$\circ\,\prime\,\prime\prime$}%
\KY{$\sin$}%
\KY{$\sin^{-1}$}%
\KY{$\cos$}%
\KY{$\cos^{-1}$}%
\KY{$\tan$}%
\KY{$\tan^{-1}$}\\

\KY{$($}%
\KY{$)$}%
\KN{$\times$}%
\KN{$\div$}%
\KN{$+$}%
\KN{$-$}%
\KN{$=$}\\

\KN{$1$}%
\KN{$2$}%
\KN{$3$}%
\KN{$4$}%
\KN{$5$}%
\KN{$6$}%
\KN{$7$}%
\KN{$8$}%
\KN{$9$}%
\KN{$0$}\\

\KN{1}%
\KN{2}%
\KN{3}%
\KN{4}%
\KN{5}%
\KN{6}%
\KN{7}%
\KN{8}%
\KN{9}%
\KN{0}\\

\end{document}

我怎样才能减少 MWE 只添加单词二乙二醇或者放射治疗在字符 LCD 中,增加矩形的尺寸(高度和长度)?

非常感谢所有用户。

在此处输入图片描述


与计算器符号相关的问题:创建 TeX 宏/代码来访问特定字体的符号的最简单方法是什么?

答案1

可能,这无关紧要。由于该LCD包只能渲染一组有限的预定义字形,为什么我们不将标准 LaTeX 的输出像素化并将其用作我们的 LCD 屏幕呢?工作流程总结如下:

  1. 使用 LaTeX 渲染液晶屏内容(就像它们是普通文本一样)
  2. 使用convert将 PDF 文件转换为图像
  3. 根据图像对屏幕内容进行像素化
  4. 在 LaTeX 中重新渲染 LCD 屏幕

结果如下: 在此处输入图片描述

在此处输入图片描述

用法

  • preamble.tex将、lcd_test.tex和放置lcd.py在同一文件夹下。
  • 运行lcd.py(在 Linux 上测试。但它无法在 Windows 上运行,因为convert与 Windows 现有的系统命令相冲突。)

问题

  1. 编译速度极慢。这就是我尝试将 LCD 屏幕保存为单独的 PDF 文件的原因。速度很慢是因为我使用 TikZ 在屏幕上绘制所有这些点。经过适当的优化后,速度会更快。
  2. 由于像素化方法过于简单,可能会出现奇怪的混叠现象。可以尝试寻找更好的字体或提出更好的像素化参数来缓解此问题。

来源

序言.tex

\usepackage[skins]{tcolorbox}
\usepackage{xcolor}
\definecolor{lcdcolor}{HTML}{6b946b}

\newlength{\lcdwidth}
\newlength{\lcdheight}
\setlength{\lcdwidth}{6cm}
\setlength{\lcdheight}{2.0cm}


\newtcolorbox{lcdscreen}{
    enhanced,
    colframe=lcdcolor,
    colback=lcdcolor
}

\newtcolorbox{lcdbox}{
    enhanced,
    colback=white,
    boxrule=0pt,
    frame hidden,
    boxsep=0pt,
    width=\lcdwidth,
    height=\lcdheight,
    arc=0pt,
    sharp corners,
    before upper={\begin{minipage}[t][\lcdheight]{\lcdwidth}\bgroup\lsstyle\Large},
    after upper={\egroup\end{minipage}},
    top=0mm,
    bottom=0mm,
    left=0mm,
    right=0mm
}

lcd_测试.tex

\documentclass{standalone}
\input{preamble.tex}
\usepackage{expl3}

\ExplSyntaxOn
\dim_new:N \l_lcd_pixel_dist_dim
\dim_set:Nn \l_lcd_pixel_dist_dim {0.15mm}
\dim_new:N \l_lcd_pixel_size_dim
\dim_set:Nn \l_lcd_pixel_size_dim {0.3mm}

\tikzset{
  pixelnode/.style={
    inner~sep=0mm,
    outer~sep=0mm,
    minimum~width=\l_lcd_pixel_size_dim,
    minimum~height=\l_lcd_pixel_size_dim,
    anchor=north~west,
    fill=black
  }
}

\fp_new:N \l_i_fp
\fp_new:N \l_j_fp

\newcommand{\drawlcd}[1]{
  \ior_open:Nn \g_tmpa_ior {#1}
  \ior_str_map_variable:NNn \g_tmpa_ior \l_tmpa_tl {
    \clist_set:NV \l_tmpa_clist \l_tmpa_tl
    \exp_args:NNx \fp_set:Nn \l_i_fp {\clist_item:Nn \l_tmpa_clist {1}}
    \exp_args:NNx \fp_set:Nn \l_j_fp {\clist_item:Nn \l_tmpa_clist {2}}
    \fp_set:Nn \l_tmpa_fp { \l_i_fp * \l_lcd_pixel_size_dim + \l_i_fp * \l_lcd_pixel_dist_dim}
    \fp_set:Nn \l_tmpb_fp { \l_j_fp * \l_lcd_pixel_size_dim + \l_j_fp * \l_lcd_pixel_dist_dim}
    \node[pixelnode] at (\fp_use:N \l_tmpb_fp pt, \fp_use:N \l_tmpa_fp pt) {};
  }
  \ior_close:N \g_tmpa_ior
}

\ExplSyntaxOff

\begin{document}%
\begin{lcdscreen}%
\begin{tikzpicture}%
\drawlcd{temp.txt}
\end{tikzpicture}%
\end{lcdscreen}%
\end{document}

液晶显示.py

import subprocess
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt

latex_template = r'''
\documentclass{standalone}
\input{preamble.tex}
\usepackage{cmbright}
\usepackage{amsmath, amssymb}
\usepackage[letterspace=100]{microtype}
\begin{document}%
\begin{lcdbox}%
%%content
\end{lcdbox}%
\end{document}
'''


screen_rows = 80
screen_cols = 240

def pixelate(content):
    latex_doc = latex_template.replace('%%content', content)
    with open('temp.tex', 'w') as outfile:
        outfile.write(latex_doc)
    # run pdflatex to compile the document
    subprocess.run(['pdflatex', '-interaction=nonstopmode', 'temp.tex'])
    # convert pdf to image
    subprocess.run(['convert', '-density', '800', 'temp.pdf','temp.png'])

    # load image
    image = np.asarray(Image.open('temp.png')).astype(np.float32) / 255.0
    if len(image.shape) > 2:
        image = image[:, :, 0]

    iticks = np.round(np.linspace(0, image.shape[0], screen_rows + 1)).astype(np.int)
    jticks = np.round(np.linspace(0, image.shape[1], screen_cols + 1)).astype(np.int)
    downsampled = np.zeros((screen_rows, screen_cols), np.bool)

    for i in range(len(iticks) - 1):
        rows = image[iticks[i]:iticks[i+1],:]
        for j in range(len(jticks) - 1):
            col = rows[:, jticks[j] : jticks[j + 1]]
            if col.min() < 0.9:
                downsampled[i,j] = True

    #plt.imshow(downsampled);plt.show()

    downsampled = np.flip(downsampled, axis=0)
    pixel_locations = np.where(downsampled)
    with open('temp.txt', 'w') as outfile:
        for i in range(pixel_locations[0].size):
            outfile.write('{},{}\n'.format(pixel_locations[0][i], pixel_locations[1][i]))

    subprocess.run(['pdflatex', '-interaction=nonstopmode', 'lcd_test.tex'])

pixelate(r'''$\displaystyle \int_a^b \frac{x^2+3x+5}{3\sin x} dx$\\
\vfill
English\hfill 12345.0''')

答案2

这是我简化事情并添加 DEG 和 RAD 的尝试。我已将其设置为 RAD 和 DEG 始终出现在与真实计算器相同的位置。您可以以相同的方式轻松添加可能需要的其他标志(例如 OCT 和 HEX)。

包装盒包装东西的方式lcd……很奇怪。我发现它在表格中表现得相当合理,所以我将下部包装tcolorboxtabular环境中。

我不太愿意让所有尺寸计算都自动化,但调整起来也并不太麻烦。

既然您说您对计算器键很满意,那我就不再担心它们了。

\documentclass{article}

\usepackage{amsmath}
\usepackage[most]{tcolorbox}
\usepackage{lcd}

\colorlet{greenish}{green!16!gray}

\LCDcolors{black}{greenish}
\LCDnoframe
\renewcommand*\textLCDcorr{0}
\DefineLCDchar{sq}{11100001000100011100000000000000000}
\DefineLCDchar{tm}{00000100010101000100010101000100000}
\DefineLCDchar{dv}{00000001000000011111000000010000000}
\DefineLCDchar{mu}{00011000011110100001000000000000000}
\DefineLCDchar{"}{11011010011001000000000000000000000}
\DefineLCDchar{deg}{01100100101001001100000000000000000}

\newcommand{\DEG}{\llap{DEG\hspace{10mm}}}
\newcommand{\RAD}{\llap{RAD\hspace{5mm}}}

\newtcolorbox{calc}[1][]{
  enhanced,bicolor,
  boxsep=0pt,
  boxrule=0pt,
  top=6pt,bottom=0pt,left=6pt,right=0pt,
  sharp corners,
  frame empty,
  colback=black!10,
  colbacklower=greenish,
  sidebyside,
  sidebyside align=top seam,
  sidebyside gap=0pt,
  righthand width=50.7mm,
  before lower=\begin{tabular}{@{}l@{}},
  after lower=\end{tabular},
  overlay={\node[inner sep=0pt, outer sep=0pt, text height=5pt, text
    depth=1pt, text width=50.7mm, fill=greenish, anchor=north
    east, font=\sffamily\tiny\bfseries, align=flush right]
    at (frame.north east) {#1};}
}

\begin{document}

\begin{calc}[\DEG\RAD]
  $(3x^2-4x^2-6x^2)=$
  \tcblower
  \large\textLCD{19}|(3{sq}-4{sq}-6{sq})| \\
  \Large\textLCD{16}|             -43| \\
\end{calc}

\begin{calc}[\DEG]
  $\div(-2\times4\times6)=$
  \tcblower
  \large\textLCD{19}|ANS{dv}(-2{tm}4{tm}6)| \\
  \Large\textLCD{16}|    0.8958333333| \\
\end{calc}

\begin{calc}
  $\cos^{-1}\text{ANS}=$
  \tcblower
  \large\textLCD{19}|cos{mu}(ANS| \\
  \Large\textLCD{16}|     26.38432975| \\
\end{calc}

\begin{calc}[\RAD]
  $\cos^{-1}\text{ANS}=$
  \tcblower
  \large\textLCD{19}|cos{mu}(ANS| \\
  \Large\textLCD{16}|     26{deg}23'3.59"| \\
\end{calc}

\end{document}

输出

相关内容