我遇到了一个相当尴尬的问题。我决定开始使用 /label 和 /reference 来更好地组织我的笔记,但每当我使用 /ref 时,它都会给我一个未定义的错误,如下所示:
代码(带前缀)是:
% chktex-file 36
% chktex-file 21
% chktex-file 8
% chktex-file 18
% chktex-file 11
% chktex-file 40
% chktex-file 3
% chktex-file 13
% chktex-file 25
% chktex-file 23
% chktex-file 29
% chktex-file 44
% chktex-file 12
% chktex-file 24
%chktex-file 9
% chktex-file 17
% chktex-file 1
\PassOptionsToPackage{english}{babel}
% You can't have ^ outside math mode or compilation will fail.
\documentclass[10pt, welsh, english, a4paper]{report}
%\documentclass[10pt, welsh, english, a4paper]{report}
\usepackage[margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{siunitx}
\usepackage{microtype}
\input{glyphtounicode}
%Marginfigure stuff
%\usepackage{marginnote}
%\usepackage{xparse}
%\usepackage{l3keys2e}
%\usepackage{changepage}
%\usepackage{sidenotes}
\usepackage{polynom} %Polynomial long division typesetting, note that this does not support imaginary or complex roots with imaginary part not equal to 0
%Indenting
\usepackage{indentfirst}
%Mathematical tools for fractions
%\usepackage{nicefrac}
\usepackage{mathtools}
% Basic Packages for Encoding (Input AND Output) and Langauge Support
%\usepackage[english]{babel} %Throws errors, just use babel by itself.
\usepackage{babel}
% Change Layout with a User-Friendly Interface
\usepackage{enumitem,url,fancyref}
%\usepackage{enumitem,geometry,url,fancyref}
% Used for bolded letters, such as the set of all reals.
\usepackage{amssymb}
% Include Pictures with a User-Friendly Interface
\usepackage{graphicx}
\usepackage{float}
\usepackage{subcaption}
\usepackage[export]{adjustbox} %Keep aspect ratio and resize
% Extended Math Support from the Famous 'American Mathematical Society'
\usepackage{amsmath}
% Physics package, mostly for the \abs command.
\usepackage{physics}
%Adjustable tables
\usepackage{tabularx}
%Additional
\usepackage{wrapfig}
\usepackage{animate} %To animate gifs, utilize imagemagick to convert the gif to several pngs by this command: (convert foo.gif foo.png), if the results are suboptimal try: (convert foo.gif -coalesce foo.png), you may probably get foo-0.png, foo-1.png... then use this code to animate them: \animategraphics[width=0.25\textwidth,autoplay,loop,nomouse,controls]{12}{./Animated/animate_}{0}{99}
\usepackage{csquotes}
\MakeAutoQuote{‘}{’}
\MakeAutoQuote*{“}{”}
\usepackage[tt=lining]{cfr-lm}
%Other optimizations
\geometry{scale=.9}
\setlength{\columnseprule}{0.4pt}
\urlstyle{sf}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\renewcommand*\headrulewidth{0pt}
%Necessary for table of contents
\usepackage[svgnames]{xcolor} % New for changing color of every paragraph randomly
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{tocloft}
\renewcommand{\cftchapfont}{\color{red}\large\bfseries}
\renewcommand{\cftsecfont}{\color{blue}}
\renewcommand{\cftsubsecfont}{\color{black}}
\renewcommand{\cftsubsubsecfont}{\color{DarkGreen}}
\renewcommand{\cftchapleader}{\color{red} \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsecleader}{\color{blue} \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsecleader}{\color{black} \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftsubsubsecleader}{\color{DarkGreen} \cftdotfill{\cftsecdotsep}}
\renewcommand{\cftchappagefont}{\color{red}%\large\bfseries
}
\usepackage[colorlinks=true,linkcolor=Indigo,linktocpage]{hyperref}
\usepackage[colorlinks=true]{hyperref}
\hypersetup{
colorlinks=true, %set true if you want colored links
linktoc=all, %set to all if you want both sections and subsections linked
linkcolor=Indigo, %choose some color if you want links to stand out
filecolor=black,
urlcolor=black,
citecolor=black
}
\renewcommand{\thesection}{\arabic{section}}
\setcounter{secnumdepth}{2}
\newcommand{\divides}{\mid}
\newcommand{\notdivides}{\nmid}
\newcommand{\vectors}{\overrightarrow}
%\newcommand{\inf}{\infty}
%\newcommand{\infinity}{\infty}
%Theorems, lemmas, corollaries enviorements
\usepackage{amsthm}
\renewcommand\qedsymbol{\(\blacksquare\)} %QED empty square to blacksquare
\newtheorem*{theorem*}{Theorem}
\newtheorem{theorem}{Theorem}
\newtheorem*{corollary*}{Corollary}
\newtheorem{corollary}{Corollary}[theorem]
\newtheorem*{lemma*}{Lemma}
\newtheorem{lemma}[theorem]{Lemma}
%Randomly color everything begin
%\usepackage{everyhook}
%
%\newcommand{\randomcolor}{%
% \definecolor{randomcolor}{RGB}
% {
% \pdfuniformdeviate 256,
% \pdfuniformdeviate 256,
% \pdfuniformdeviate 256
% }%
% \color{randomcolor}%
%}
%
%\PushPostHook{thesection}{\randomcolor}
%Randomly color everything end
%Randomly color section begin
%\newkomafont{secnum}{\color{LightSteelBlue}}
%\usepackage{etoolbox}
%\renewcommand*\do[1]{%
% \newkomafont{#1number}{}%
% \expandafter\renewcommand\csname#1format\endcsname{%
% {\usekomafont{secnum}\usekomafont{#1number}\csname the#1\endcsname\autodot}\enskip%
% }%
%}
%\docsvlist{section,subsection,subsubsection,paragraph,subparagraph}
%Randomly color section end
%Randomly color sections
%\renewcommand*{\sectionformat}{%
% \textcolor{LightSteelBlue}{\thesection}\autodot\enskip%
%}
%\renewcommand*{\subsectionformat}{%
% \textcolor{LightSteelBlue}{\thesubsection}\autodot\enskip%
%}
%Randomly Color sections end
%\partformat
%\chapterformat
%\sectionformat
%\subsectionformat
%\subsubsectionformat
%\paragraphformat
%\subparagraphformat
%New method
%Decoration of header and footer
%For fancyhead, /thepage prints the number of current page, /leftmark current chapter name, /rightmark current section name, /chaptername the name "chapter" in the current language. /thechapter current chapter number, /thesection current section number.
%\chapter{Using different page styles}
\renewcommand{\sectionmark}[1]{\markright{#1}}
\fancyhead[LE,RO]{\emph{Written by Faycal Kilali}} %RIght corner of header text
\fancyhead[RE,LO]{\rightmark} %Left corner of header text
\fancyfoot[CE,CO]{\thepage} % Below footer text
%\fancyfoot[LE,RO]{\thepage} % Rights side below footer text
\renewcommand{\headrulewidth}{2pt}
%\renewcommand{\footrulewidth}{1pt}
%%Decoration of header and footer
%\renewcommand{\subsubsectionmark}[1]{\markright{\thesubsubsection\ #1}} %Makes it possible for subsection and subsubsection to be part of /rightmark
%\fancyhead[LE,RO]{\emph{Written by Faycal Kilali}} %RIght corner of header text
%\fancyhead[RE,LO]{\rightmark} %Left corner of header text
%\fancyfoot[CE,CO]{\emph{Written by Faycal Kilali}} % Below footer text
%\fancyfoot[LE,RO]{\thepage} % Rights side below footer text
%\renewcommand{\headrulewidth}{2pt}
%\renewcommand{\footrulewidth}{1pt}
\usepackage{amsthm}
\usepackage{booktabs}
\definecolor{paleblue}{rgb}{0.69, 0.93, 0.93}
\definecolor{lightgray}{rgb}{0.83, 0.83, 0.83}
\definecolor{lightyellow}{rgb}{1.0, 1.0, 0.88}
\definecolor{lightgray}{gray}{0.9}
\pdfgentounicode=1
\title{Compilation envirorement - for debugging and or writing LaTeX code to implement to other}
\author{Faycal Kilali\thanks{"It is not knowledge, but the act of learning, not possession but the act of getting there, which grants the greatest enjoyment." - Carl Friedrich Gauss}}
\date{\today}
\begin{document}
\begin{titlepage}
\maketitle
\end{titlepage}
\expandafter\let\expandafter\oldproof\csname\string\proof\endcsname
\let\oldendproof\endproof
\renewenvironment{proof}[1][\proofname]{%
\oldproof[\ttfamily \scshape \Large \color{red}{\textbf{Proof}}]%
}{\oldendproof}
%Below is if you dont' wanna re-define the proof environment.
%\newenvironment{proofbolded}[1][\proofname]{%
% \proof[\ttfamily \scshape \large Exhibit (yes, ``#1'')]
%}{\endproof}
%TESTING%
\section{Test}
\begin{gather}
1 = potato \label{a}
\end{gather}
Lets go \ref{a} test
\end{document}
任何帮助,将不胜感激。
编辑 (1):我正在使用 Virtual Studio Code 和 latex-workshop、miktex、bibitex 和 pdflatex。我想补充一下,我是
答案1
\label{a}
无论如何,在环境中使用gather*
都是没用的。
标签将被定义(并且不可能知道为什么你没有获得它),但\ref{a}
会指向某个随机值,很可能是最后一个部分(无论它是哪个级别)的编号。在下面的示例代码中,它指的是 2,因为有第二个部分。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\section{Test one}
Text
\section{Test two}
\begin{gather*}
1=Potato \label{a}
\end{gather*}
\ref{a}
\end{document}
当然,如果你使用,则引用方程编号gather
,但是gather*
,不是设定一个数字。
答案2
我能够通过某个我根本找不到的 tex stackexchange 帖子解决这个问题(我尝试了一个小时但无法再找到它),无论如何,该特定帖子的解决方案是将我的 latex-workshop 配方更改为以下内容:
"latex-workshop.latex.recipes": [
{
"name": "luatex -> biber -> luatex*2",
"tools": [
"luatex",
"biber",
"luatex",
"luatex"
]
},
],
"latex-workshop.latex.tools": [{
{,
"name": "pdflatex",
"command": "pdflatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
},
{
"name": "biber",
"command": "biber",
"args": [
"%DOCFILE%"
]
},
{
"name": "luatex",
"command": "luatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
},
]