将每个符号定义为 LaTeX 中的命令

发布于 2024-07-25 12:21:41 字数 282 浏览 2 评论 0原文

我正在开发一个大型项目,涉及用 LaTeX 排版的多个文档。 我希望在使用符号时保持一致,因此为整个项目中具有特定含义的每个符号定义一个命令可能是一个好主意。 有人对这个有经验么? 有什么需要注意的问题吗?

更具体一点。 比如说,在整个文档中,我将通过脚本 P 来表示称为可渗透性的东西,这是否是一个定义的想法

\providecommand{\permeability}{\mathscr{P}}

,或者这更像是“为 $n$ 定义命令”的情况?

I'm working on a large project involving multiple documents typeset in LaTeX. I want to be consistent in my use of symbols, so it might be a nice idea to define a command for every symbol that has a specific meaning throughout the project. Does anyone have any experience with this? Are there issues I should pay attention to?

A little more specific. Say that, throughout the document I would denote something called permability by a script P, would it be an idea to define

\providecommand{\permeability}{\mathscr{P}}

or would this be more like the case "defining a command for $n$"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

往日情怀 2024-08-01 12:21:41

一些提示:

  • 仅当先前未定义该命令时,使用 \providecommand 才会定义该命令。 因此,如果您没有得到预期的结果,您可能正在尝试定义一个已在其他地方定义的命令。
  • 如果您使用 \ensuremath 将数学包含在命令中,则无论您发出命令时是否处于数学模式,它都会执行正确的操作:

    \providecommand{\permeability}{\ensuremath{\mathscr{P}}} 
      现在我可以轻松地在文本中使用 \permeability 或在数学模式中使用 $\permeability$ 。 
      
  • 使用您自己的命令可以让您轻松更改以后某些内容的印刷表示形式。 例如:

    \newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}} 
      

    会将 \vect{x} 打印为粗体 x。 如果您后来决定更喜欢矢量上方的箭头,您可以将命令更改为:

    \newcommand{\vect}[1]{\ensuremath{\vec{#1}}} 
      

A few tips:

  • Using \providecommand will define that command only if it's not been previously defined. So if you're not getting the results you expected, you may be trying to define a command that's been defined elsewhere.
  • If you wrap the math in your commands with \ensuremath, it will do the right thing regardless of whether you're in math mode when you issue the command:

    \providecommand{\permeability}{\ensuremath{\mathscr{P}}}
    Now I can easily use \permeability in text or $\permeability$ in math mode.
    
  • Using your own commands allows you to easily change the typographical representation of something later. For instance:

    \newcommand{\vect}[1]{\ensuremath{\mathbf{#1}}}
    

    would print \vect{x} as a boldfaced x. If you later decide you prefer arrows above your vectors, you could change the command to:

    \newcommand{\vect}[1]{\ensuremath{\vec{#1}}}
    
就是爱搞怪 2024-08-01 12:21:41

我一直在为任何具有特定含义并且比单个符号长的东西这样做,主要是为了节省打字:

\newcommand{\objId}{\mbox{$\mathit{objId}$}\xspace} 
\newcommand{\insOp}[1]{#1\mbox{$^+$}\xspace} 
\newcommand{\delOp}[1]{#1\mbox{$^-$}\xspace}

但是后来我注意到我不再犯不一致的错误(objId vs ObjId vs ObjID),所以我同意这是一个好主意。

但是,我不确定如果输出中的符号是单个拉丁符号,这是否是一个好主意,如下所示:

\newcommand{\numOfObjs}{$n$}

即使为其定义了命令,也很容易键入单个符号并忘记它。

编辑:使用您的示例恕我直言,定义 \permeability 是一个好主意,因为它不仅仅是一个您必须在没有命令的情况下输入的 P 。 但这是千钧一发。

I have been doing this for anything that has a specific meaning and is longer than a single symbol, mostly to save typing:

\newcommand{\objId}{\mbox{$\mathit{objId}$}\xspace} 
\newcommand{\insOp}[1]{#1\mbox{$^+$}\xspace} 
\newcommand{\delOp}[1]{#1\mbox{$^-$}\xspace}

However then I noticed that I stopped making inconsistency errors (objId vs ObjId vs ObjID), so I agree that it is a nice idea.

However I am not sure if it is a good idea in case symbols in the output are, well, single Latin symbols, as in:

\newcommand{\numOfObjs}{$n$}

It is too easy to type a single symbol and forget about it even though a command was defined for it.

EDIT: using your example IMHO it'd be a good idea to define \permeability because it is more than a single P that you have to type in without the command. But it's a close call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文