在 LyX 中引用 tcolorbox

在 LyX 中引用 tcolorbox

我在 LyX 中的 tufte-book 类中编写并定义了一个自定义 tcolorbox(LyX 中的彩色框),如下所示:在此处输入图片描述 现在,我在“颜色框选项”中输入文本label={truck}并引用,\ref={truck}引用结果为??。即使我从 LyX 参考文档中复制了彩色框的工作示例,也不起作用。插入 在此处输入图片描述 结果是 在此处输入图片描述 既然它在参考文档中起作用,那么它一定与自定义框 2 或文档类的定义有关?任何帮助解决此问题的帮助都将不胜感激。

编辑:以下是一个文档示例:

    #LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass tufte-book
\begin_preamble
\usepackage{xcolor} % for colour
\usepackage{lipsum} % just for sample text
\usepackage{physics}
\usepackage{caption}

% add numbers to chapters, sections, subsections
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{1}
\definecolor{oucrimsonred}{rgb}{0.6, 0.0, 0.0}
\definecolor{persianred}{rgb}{0.8, 0.2, 0.2}
\definecolor{persimmon}{rgb}{0.93, 0.35, 0.0}
\titleformat{\chapter}%
  {\huge\rmfamily\itshape\color{oucrimsonred}}% format applied to label+text
  {\llap{\colorbox{oucrimsonred}{\parbox{1.5cm}{\hfill\itshape\huge\color{white}\thechapter}}}}% label
  {2pt}% horizontal separation between label and title body
  {\leavevmode\newline}% before the title body
  [{\titlerule[0.8pt]}]% after the title body

% section format
\titleformat{\section}%
  {\normalfont\LARGE\itshape\color{persianred}}% format applied to label+text
  {\vspace{2em}\llap{\colorbox{persianred}{\parbox{1.5cm}{\hfill\color{white}\thesection}}}}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

% subsection format
\titleformat{\subsection}%
  {\normalfont\large\itshape\color{persimmon}}% format applied to label+text
  {\llap{\colorbox{persimmon}{\parbox{1cm}{\hfill\color{white}\thesubsection}}}}% label
  {1em}% horizontal separation between label and title body
  {}% before the title body
  []% after the title body

\def\mathnote#1{%
  \tag*{\rlap{\hspace\marginparsep\smash{\parbox[t]{\marginparwidth}{%
  \footnotesize#1}}}}
}
\numberwithin{equation}{chapter}
\setlength{\JustifyingParindent}{0pt}
\setlength{\parskip}{1em}
\newcommand{\me}{\mathrm{e}}
\newcommand{\nth}{n^\text{th}}
\addtolength{\jot}{1em}

\usepackage{titlesec}
\titlespacing*{\section}
{0pt}{2.2em plus 1ex minus .2ex}{4.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{5.5ex plus 1ex minus .2ex}{4.3ex plus .2ex}

\makeatletter
\g@addto@macro \normalsize {%
 \setlength\abovedisplayskip{10pt plus 2pt minus 2pt}%
 \setlength\belowdisplayskip{10pt plus 2pt minus 2pt}%
}
\makeatother
\end_preamble
\use_default_options true
\begin_modules
theorems-ams-chap-bytype
theorems-ams-extended-chap-bytype
tcolorbox
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine natbib
\cite_engine_type authoryear
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 2
\tocdepth 2
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout New Color Box Type

\begin_inset Argument 1
status open

\begin_layout Plain Layout

auto counter, number within=chapter
\end_layout

\end_inset


\begin_inset Argument 2
status open

\begin_layout Plain Layout

cBoxB
\end_layout

\end_inset


\begin_inset Argument 3
status open

\begin_layout Plain Layout

1
\end_layout

\end_inset


\begin_inset Argument 4
status open

\begin_layout Plain Layout

\end_layout

\end_inset

colback=red!5!white, colframe=red!75!black, title=
\backslash
textbf{Definition~
\backslash
thetcbcounter #1},before skip=20pt plus 2pt,after skip=20pt plus 2pt
\end_layout

\begin_layout Standard
\begin_inset Flex Custom Color Box 2
status open

\begin_layout Plain Layout
\begin_inset Argument 1
status open

\begin_layout Plain Layout
Mass–energy equivalence, label={Einstein}
\end_layout

\end_inset


\begin_inset Formula 
\[
E=mc^{2}.
\]

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Standard
To reference the box, insert the command
\end_layout

\begin_layout Standard

\series bold

\backslash
ref{name}
\end_layout

\begin_layout Standard
as \SpecialChar TeX
 code to the text where the reference should appear.
\end_layout

\begin_layout Standard
This is the reference to Example
\begin_inset space \space{}
\end_inset


\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
ref{Einstein}
\end_layout

\end_inset

.
 
\end_layout

\end_body
\end_document

答案1

我在下面的文件中所做的是使用两个参数而不是一个参数来定义 tcolorbox,第一个参数用于可选定义标题,第二个参数用于标签。

我应该指出,TeX 会忽略命令名后的空格,这就是为什么 中没有空格\thetcbcounter #1,我假设你想要这里有一个空格,所以我把它改成了\thetcbcounter\ #1

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass tufte-book
\begin_preamble

\end_preamble
\use_default_options true
\begin_modules
tcolorbox
\end_modules
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry true
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine natbib
\cite_engine_type authoryear
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 2
\tocdepth 2
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout New Color Box Type
\begin_inset Argument 1
status open

\begin_layout Plain Layout

auto counter, number within=chapter
\end_layout

\end_inset


\begin_inset Argument 2
status open

\begin_layout Plain Layout

cBoxB
\end_layout

\end_inset


\begin_inset Argument 3
status open

\begin_layout Plain Layout

2
\end_layout

\end_inset


\begin_inset Argument 4
status open

\begin_layout Plain Layout

\end_layout

\end_inset

colback=red!5!white, colframe=red!75!black, title=
\backslash
textbf{Definition~
\backslash
thetcbcounter
\backslash
 #1},before skip=20pt plus 2pt,after skip=20pt plus 2pt, label={#2}
\end_layout

\begin_layout Standard
\begin_inset Flex Custom Color Box 2
status open

\begin_layout Plain Layout
\begin_inset Argument 1
status open

\begin_layout Plain Layout
Mass–energy equivalence
\end_layout

\end_inset


\begin_inset Argument 2
status open

\begin_layout Plain Layout
Einstein
\end_layout

\end_inset


\begin_inset Formula 
\[
E=mc^{2}.
\]

\end_inset


\end_layout

\end_inset


\end_layout

\begin_layout Standard
To reference the box, insert the command
\end_layout

\begin_layout Standard

\series bold

\backslash
ref{name}
\end_layout

\begin_layout Standard
as \SpecialChar TeX
 code to the text where the reference should appear.
\end_layout

\begin_layout Standard
This is the reference to Example
\begin_inset space \space{}
\end_inset


\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
ref{Einstein}
\end_layout

\end_inset

.
 
\end_layout

\end_body
\end_document

请注意,我删除了你的序言,因为演示不需要它,而且我想使代码更短。

如果你想在 LyX 中自定义你的定理,我可以推荐一个我为此目的编写的模块,可以在这里。使用此模块,您可以获得文件中当前的样式,但您可以像往常一样使用 LyX 的参考系统,并且定理布局将看起来相同(在 LyX 的 GUI 内部)与通常的定理模块提供的普通定理相同(因此您可以看到定义的编号)。

相关内容