我正在尝试在 LaTeX 中包含一些自定义符号。因此,我有一些要导出为 PDF 的矢量图形图像,例如:
并且我使用 将它们包含在 LaTeX 中
\newcommand*\mysymbol{\includegraphics{mysymbol.pdf}}
。
我有两个问题:
方程式中的定位不正确(尽管图像本身没有边框,但它位于线之上):
我无法将其用作下标(我想要这样做)。例如,
$H_\mysymbol$
抛出以下错误:./mytex.tex:1000: Missing { inserted. <to be read again> \let l.1000 $H_\mysymbol $ ?
答案1
\documentclass[fleqn]{article}
\usepackage{graphicx}
\newcommand\xmysymbol{\raisebox{-.7ex}{\includegraphics[height=2.2ex]{mysymbol}}}
\newcommand\mysymbol{{\mathchoice{\xmysymbol}{\xmysymbol}{\hbox{\scriptsize\xmysymbol}}{\hbox{\tiny\xmysymbol}}}}
\begin{document}
\[\chi(x \in \mysymbol)\]
$\chi(x \in \mysymbol)$
$X_\mysymbol + X_{x_\mysymbol}$
\end{document}
答案2
只需一个技巧,而不是多个。;-)
\documentclass{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\newcommand*{\mysymbol}{%
\text{% change size in subscripts or superscripts
\includegraphics[
height=1.5ex,% adjust to suit
valign=M,% center vertically
raise=\fontdimen22\textfont2,% but raise it to the formula axis
]{YWWMA}}
}
\begin{document}
\[
\frac{1}{2}+\mysymbol-
H_\mysymbol \in \mysymbol^{\mysymbol^\mysymbol}
\]
\end{document}
答案3
评论:
该符号位于基线。您可能希望将其置于数学轴的中心(例如
+
,,×
...)。符号的高度未定义。示例使用的高度为
H
。下标和上标是不是参数,因此,如果只有一个标记,则大括号可以省略的规则不适用。只有当标记扩展为数学符号或子公式时,它才有效。大括号有效,因为它们形成了一个子公式。
示例使用
\resizebox
,因为它比 选项更灵活\includegraphics
。然后可以使用其他内容(tikzpicture
,...)代替\includegraphics
。通过使用盒子寄存器可以避免重复使用
\includegraphics
。图像存储在盒子寄存器中\mysymbolbox
并在宏中重复使用\mysymbol
。这还可以避免文件.log
充斥着有关图像的信息数据mysymbol
。
完整示例:
\documentclass{article}
\usepackage{graphicx}
\newsavebox{\mysymbolbox}
\sbox{\mysymbolbox}{\includegraphics{myimage}}
\makeatletter
\newcommand*{\mysymbol}{%
{% subformula in math that allows: H_\mysymbol
\mathpalette{\@mysymbol}{}%
}%
}
\newcommand*{\@mysymbol}[2]{%
% #1: math style
% #2: unused
\settoheight{\dimen@}{$#1H$}% \dimen@ is a local scratch dimen register
\vcenter{\hbox{% vertical centering around math axis
\resizebox*{!}{\dimen@}{% total height = \dimen@
\usebox{\mysymbolbox}%
}%
}}%
}
\makeatother
\begin{document}
\[
H_\mysymbol \in \mysymbol^{\mysymbol^\mysymbol}
\]
\end{document}
蒂克兹
答案在符号如果没有 TikZ,标签就不完整(至少通常如此):
\documentclass{article}
\usepackage{tikz}
\newsavebox\myimagebox
\sbox\myimagebox{% avoid space by line end
\begin{tikzpicture}[
x=1ex,
y=1ex,
line width=.7pt,% between semithick and thick
line join=round,
]
\draw (0,0) -- (1,-1) -- (3,1) -- (4,0) -- (3,-1) -- (1,1) -- cycle;
\fill (0,0) -- (.5,-.5) -- (1.5,.5) -- (1,1) -- cycle;
\end{tikzpicture}% avoid space by line end
}
\makeatletter
\newcommand*{\mysymbol}{%
{% subformula in math that allows: H_\mysymbol
\mathpalette{\@mysymbol}{}%
}%
}
\newcommand*{\@mysymbol}[2]{%
% #1: math style
% #2: unused
\settoheight{\dimen@}{$#1H$}% \dimen@ is a local scratch dimen register
\vcenter{\hbox{% vertical centering around math axis
\resizebox*{!}{\dimen@}{% total height = \dimen@
\usebox\myimagebox
% \includegraphics{mysymbol}%
}%
}}%
}
\makeatother
\begin{document}
\[
H_\mysymbol \in \mysymbol^{\mysymbol^\mysymbol}
\]
\end{document}
变体
\documentclass{article}
\usepackage{amstext}
\usepackage{tikz}
\newcommand*{\mysymbol}{%
\text{%
\pgfmathsetmacro\mysymbolHeight{height("$H$")}%
\pgfmathsetmacro\mysymbolLineWidth{\mysymbolHeight*.07}%
\pgfmathsetmacro\MathAxis{height("$\vcenter{}$")}%
\begin{tikzpicture}[
x=\mysymbolHeight,
y=\mysymbolHeight,
line width=\mysymbolLineWidth,
line join=round,
baseline=-\MathAxis,
]
\draw (0,0)--(.5,-.5)--(1.5,.5)--(2,0)--(1.5,-.5)--(.5,.5)--cycle;
\fill (0,0)--(.25,-.25)--(.75,.25)--(.5,.5)--cycle;
\end{tikzpicture}%
}%
}
\begin{document}
\[
H_\mysymbol \in \mysymbol^{\mysymbol^\mysymbol}
\]
\end{document}
答案4
\newcommand*\mysymbol{\raisebox{-1ex}{\includegraphics{mysymbol}}}
和
$H_{\mysymbol}$