0

I have been trying to implement the code given in the answer by percusse in \foreach with \newcommand how to use them together?. The code seems to work, however TeXstudio does not recognize the new commands (i.e. in highlights them orange).

Here is the code in my situation:

\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}}
}

which allows me to write things like $\calA$ to display mathcal A. However, the \calA appears as an "unrecognized command" (i.e. it is highlighted orange) in TeXstudio.

I have all of the usual packages like amsmath, amsfont, amssymb, etc. loaded.

Question: how can I get these custom commands to be recognized by TeXstudio?


For clarity, here is all of the packages that I have loaded:

%---------------------------------------------------------------------------
%                           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 %---------------------------------------------------------------------------

Dave
  • 123
  • 2
    You could write a custom .cwl file and list all the new commands there. However is this really worth the effort? If textudio recognises or not recognises a command does not have any influence on the result. – samcarter_is_at_topanswers.xyz Mar 22 '23 at 22:44
  • @samcarter_is_at_topanswers.xyz I think to do that I would need to list each individual command, right? Like \calA, \calB, \calC, etc. My issue is definitely not significant, but I am still curious if there is a way to solve this problem. – Dave Mar 22 '23 at 22:57
  • 1
    See the texstudio manual and many examples here – mbert Mar 22 '23 at 23:18
  • You could just use \cal A, \cal B and define \newcommand*\scr[1]{\mathscr{#1}} and \newcommand*\Frak[1]{\mathfrak{#1}} and use \scr A as well as \Frak B without having to define 52×3 commands. – Qrrbrbirlbel Mar 23 '23 at 00:50
  • @Qrrbrbirlbel it's a very minor time-saver, but I have it all as one command (e.g. \calA vs. \cal A) with no spaces so that way when I use it in a subscript or something, I don't need to use curly braces. – Dave Mar 23 '23 at 01:43
  • I usually turn off this function in TeXstudio: Options / Configure TeXstudio / Editor / Syntax (no checked) – hair-splitter Mar 23 '23 at 07:10

0 Answers0