我一直在尝试实现 percusse 在答案中给出的代码\foreach 与 \newcommand 如何一起使用?。代码似乎可以工作,但是 TeXstudio 无法识别新命令(即以橙色突出显示它们)。
以下是我的情况的代码:
\foreach \x in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}{
\expandafter\xdef\csname cal\x\endcsname{\noexpand\mathcal{\x}}
\expandafter\xdef\csname scr\x\endcsname{\noexpand\mathscr{\x}}
\expandafter\xdef\csname frak\x\endcsname{\noexpand\mathfrak{\x}}
}
它允许我编写诸如$\calA$
显示数学 A 之类的东西。但是,\calA
在 TeXstudio 中它显示为“无法识别的命令”(即以橙色突出显示)。
我已经加载了所有常用的软件包,例如 amsmath、amsfont、amssymb 等。
问题:我怎样才能让 TeXstudio 识别这些自定义命令?
为了清楚起见,这里是我已加载的所有包:
%---------------------------------------------------------------------------
% DOCUMENT CLASS
%---------------------------------------------------------------------------
\documentclass[12pt, letterpaper, leqno]{amsart}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[foot]{amsaddr}
%---------------------------------------------------------------------------
% BIBLATEX
%---------------------------------------------------------------------------
\usepackage[style=alphabetic, maxnames=99]{biblatex}
\AtBeginBibliography{\small}
\usepackage{microtype}
\microtypesetup{protrusion=false}
%---------------------------------------------------------------------------
% HYPERREFS
%---------------------------------------------------------------------------
\usepackage{xr-hyper}
\usepackage{xstring}
\usepackage{hyperref}
\usepackage{url}
\hypersetup{
colorlinks = true,
urlcolor = cyan,
linkcolor = blue,
citecolor = blue
}
\makeatletter
\newcommand{\labeltext}[3][]{%
\@bsphack%
\csname phantomsection\endcsname% in case hyperref is used
\def\tst{#1}%
\def\labelmarkup{}% How to markup the label itself
%\def\refmarkup{\labelmarkup}% How to markup the reference
\def\refmarkup{}%
\ifx\tst\empty\def\@currentlabel{\refmarkup{#2}}{\label{#3}}%
\else\def\@currentlabel{\refmarkup{#1}}{\label{#3}}\fi%
\@esphack%
\labelmarkup{#2}% visible printed text.
}
\makeatother
%---------------------------------------------------------------------------
% FONTS AND MATH PACKAGES
%---------------------------------------------------------------------------
\usepackage[english]{babel}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{amssymb}
%\usepackage{mathabx}
\usepackage{mathrsfs}
\usepackage{xpatch}
\usepackage{stmaryrd}
%---------------------------------------------------------------------------
% TIKZ AND DIAGRAMS PACKAGES
%---------------------------------------------------------------------------
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{arrows.meta,automata,positioning}
\usetikzlibrary{svg.path}
\usepackage{amscd}
\usepackage{quiver}
\usepackage{tikzit}
%---------------------------------------------------------------------------
% TABLES, FIGURES, LISTS PACKAGES
%---------------------------------------------------------------------------
\usepackage{float}
\setcounter{MaxMatrixCols}{15}
\usepackage{enumitem}
\usepackage[labelfont=bf]{caption}
\usepackage[linewidth=0pt]{mdframed}
\usepackage{subfig}
%---------------------------------------------------------------------------
% HEADERS, FOOTNOTES, CHAPTERS, ETC. PACKAGES
%---------------------------------------------------------------------------
\usepackage{fancyhdr}
\usepackage[bottom, perpage]{footmisc}
%\usepackage{titlesec}
\usepackage{etoolbox}
%_____Bold sections
\patchcmd{\section}{\scshape}{\bfseries}{}{}
\makeatletter
\renewcommand{\@secnumfont}{\bfseries}
\makeatother
%_____Minimal spacing chapter titles
%\titleformat{\chapter}[hang]{\huge\bfseries\doublespacing}{\thechapter}{20pt}{}{}
%\titlespacing*{\chapter}{0pt}{-30pt}{40pt}
%---------------------------------------------------------------------------
% GENERAL FORMATTING
%---------------------------------------------------------------------------
\allowdisplaybreaks
\usepackage{subfiles}
\usepackage{setspace}
%\doublespacing
\setlength{\parskip}{0.25em}
%_____Numbering equations, figures, and theorems all the same by section
\numberwithin{equation}{section}
\numberwithin{figure}{section}
\makeatletter
\let\c@equation\c@figure
\makeatother
%---------------------------------------------------------------------------