如何僅使用程式碼建立這樣的新符號?

如何僅使用程式碼建立這樣的新符號?

我需要一些新符號,但我不知道如何創建它們。我試圖找出這些符號是否已經在 LaTeX 包中,但事實並非如此。所以最後我在這裡問。

每個答案都會對我非常有幫助,因為我是使用 TeX 的新手。

我想要的命令將在數學模式下使用。我想要三個命令,但其中兩個只是另一個命令的變體\lrod{ }。這個名字來自左手握住的探礦工具「L-rod」。

  1. \lrod{ }。左端垂直向下彎曲的桿。請參考下圖。
  2. \rrod{ }。的右側版本\lrod{ }
  3. \stapler{ }。的雙面版本\lrod{ }

\lrod{ }將一個字母或一串字母作為參數。然後它為我們提供了被其上方適當水平長度的“左手 L 桿”覆蓋的字母(字串)。也就是說,如果我輸入

$\lrod{a}$, $\lrod{abc}$ and $\lrod{a \vphantom b},

那我應該得到以下內容: /lrod 的例子

正如您所看到的,每個字母的頂部高度應該不同。但如果我使用\vphantom,那麼我應該能夠修復它。

此外,我希望我可以自己修剪你的每一部分的長度\lrod:長的垂直部分和短的水平部分。所以請不要使用 pdf 圖像給我答案,而只使用程式碼。

\rrod{ }和命令\stapler{ }可以用類似的方式來描述。這是一個範例圖像。

符號範例

正如您所看到的,對於同一個字母,三個符號的頂部高度和寬度應該相等。

最後,符號的寬度必須比下面的字母稍窄,這樣當我輸入以下內容時,它們之間就會有間隙。

$\lrod{b}\rrod{b}\stapler{b}$

多謝。

答案1

您基本上是由 定義的\stapler巨集。該套件還允許調整規則的寬度。預設寬度有點大,所以我把它改小了。我定義並類似於\overbracketmathtoolslrod\rrod\overbracket

\documentclass{article}

\usepackage{mathtools}

\newcommand*{\stapler}[1]{{\overbracket[.4pt][.4\fontdimen5\textfont2]{#1}}}

\makeatletter
\newcommand*{\lrod}[1]{%
   \vbox{\m@th\ialign{##\crcr
          \downbracketend{.4pt}{.4\fontdimen5\textfont2}%
          \leaders \vrule \@height .4pt \@depth \z@ \hfil
        \crcr
          \noalign{\kern .2\fontdimen5\textfont2 \nointerlineskip}%
          $\displaystyle{#1}$%
        \crcr}}%
}

\newcommand*{\rrod}[1]{%
   \vbox{\m@th\ialign{##\crcr
          \leaders \vrule \@height .4pt \@depth \z@ \hfil
          \downbracketend{.4pt}{.4\fontdimen5\textfont2}%
        \crcr
          \noalign{\kern .2\fontdimen5\textfont2 \nointerlineskip}%
          $\displaystyle{#1}$%
        \crcr}}%
}

\makeatother

\begin{document}

$\lrod{a}$
$\lrod{\vphantom{b}a}$
$\lrod{b}$
$\lrod{ab}$
$\lrod{abc}$

\medskip
$\rrod{a}$
$\rrod{\vphantom{b}a}$
$\rrod{b}$
$\rrod{ab}$
$\rrod{abc}$

\medskip
$\stapler{a}$
$\stapler{\vphantom{b}a}$
$\stapler{b}$
$\stapler{ab}$
$\stapler{abc}$

\end{document}

在此輸入影像描述

\fontdimen5\textfont2我從程式碼中採用了前面的參數mathtools。您可以調整它以滿足您的需求。

答案2

下面透過在使用(內部允許下標和上標)\rule測量參數的大小後使用 LaTeX 繪製規則來提供您的符號。\sbox\mathpalette

\documentclass[]{article}

\makeatletter
\newcommand*\stapler@ht{.2ex} % height of the ticks on both ends
\newcommand*\stapler@wd{.1ex} % thickness of the rules
\newcommand*\stapler@dv{.2ex} % padding vertically between argument and symbol
\newcommand*\stapler@di{.2ex} % padding applied on either end of the argument
\newcommand*\stapler@do{.2ex} % padding applied on either end around the symbol
\newsavebox\stapler@box
\newif\ifstapler@left
\newif\ifstapler@right
\newcommand*\@stapler[2]
  {%
    \kern\stapler@do\relax
    \sbox\stapler@box{$#1\kern\stapler@di\relax#2\kern\stapler@di\relax$}%
    \ifstapler@left
      \rule
        [\dimexpr\ht\stapler@box+\stapler@dv]
        {\stapler@wd}
        {\dimexpr\stapler@ht+\stapler@wd/2}%
      \kern-\stapler@wd
    \fi
    \rlap
      {%
        \rule
          [\dimexpr\ht\stapler@box+\stapler@dv+\stapler@ht-\stapler@wd/2]
          {\wd\stapler@box}
          {\stapler@wd}%
      }%
    \usebox\stapler@box
    \ifstapler@right
      \kern-\stapler@wd
      \rule
        [\dimexpr\ht\stapler@box+\stapler@dv]
        {\stapler@wd}
        {\dimexpr\stapler@ht+\stapler@wd/2}%
    \fi
    \kern\stapler@do\relax
  }
\newcommand*\stapler{\stapler@lefttrue\stapler@righttrue\mathpalette\@stapler}
\newcommand*\lrod{\stapler@lefttrue\stapler@rightfalse\mathpalette\@stapler}
\newcommand*\rrod{\stapler@leftfalse\stapler@righttrue\mathpalette\@stapler}
\makeatother

\begin{document}
$\lrod{a}\rrod{b}$

$\lrod{abc}\lrod{\vphantom{abc}a}$

$\lrod{b}\stapler{b}\rrod{b}$

$E^{\lrod{b}\stapler{b}\rrod{b}^{\lrod{a}\stapler{a}\rrod{a}}}$
\end{document}

您可以透過變更參數的定義來自訂它的外觀。

在此輸入影像描述

相關內容