使用cref和tcolorbox時如何在TeXstudio中顯示參考建議?

使用cref和tcolorbox時如何在TeXstudio中顯示參考建議?

編輯:這個問題現在此功能請求在 TXS Github 上。

非常挑剔的問題。我很高興使用 TeXstudio、tcolorbox 套件和 Cleveref。在 TXS 中,鍵入cref會觸發一個彈出式選單,其中列出了所有可用標籤,使用者可以直接選擇相關標籤。當使用對定理框的引用時,這個方便的系統似乎被破壞了。

詳細案例 此範例使用tcolorbox, amsmath(cleveref 所需)cleveref和 tcolorbox 庫theorems(所有內容都在最小工作範例中鍵入)。

該指令\newtcbtheorem會建立一種新類型的 tcolorbox 定理框,如下所示

\newtcbtheorem[crefname={mybox}{myboxes}]{mybox}{My super theorem}{}{mybox}

這裡,第一個可選參數[]將設定cleveref名稱,該參數{mybox}是盒子環境的名稱,{My super theorem}是標題中顯示的名稱,空參數{}是盒子選項,最後一個{mybox}是引用的前綴。例如,當創建一個盒子時

\begin{mybox}{The title}{thelabel} 
    Hello
\end{mybox}

第一個參數是框的標題,第二個參數建立一個我們可以透過 呼叫的參考\cref{mybox:thelabel}。 Latex 部分中的所有內容都運作良好,但編輯器似乎不知道這些標籤的存在,使用者需要要么記住其所有標籤,要么在文件中溜溜。

圖中範例: 在此輸入影像描述

期望的行為 能夠mybox:thelabel在彈出視窗的建議清單中看到。任何幫助表示讚賞!

版本如果相關的話,我正在使用Ubuntu 22.04、TeXstudio 4.3.1、tcolorbox 5.0.2、amsmath v2.17l和cleveref v0.21.4。

工作範例

\documentclass{article}

\usepackage{tcolorbox}
\usepackage{amsmath} % required for cleverref
\usepackage{cleveref}

\tcbuselibrary{theorems}
\newtcbtheorem[crefname={mybox}{myboxes}]{mybox}{My super theorem}{}{mybox}

\begin{document}

    Example of the question:
    \begin{mybox}{The title}{thelabel} 
        Hello
    \end{mybox}

    This is a nice document, what a superb result we have here:
    \begin{mybox}{Micchelli 1986}{micchelli}
        Let $D$ be a distance matrix, i.e. $D_{ij} = d(x_i,x_j)$ for $n$ distinct points $(x_i)_{i=1}^n$ of an euclidian space. Then $D$ is invertible. 
    \end{mybox}
    
    This theorem applies for equations of the type
    \begin{align}\label{normalref}
        \sum_{i=1}^n c_i d(x_i, x_j) = 0 \quad\quad \forall 1 \leq j \leq n,
    \end{align}
    and the popup correctly displays the \texttt{normalref}: indeed, \cref{normalref} was displayed. However, although \cref{mybox:micchelli} works nicely, it was not displayed. 
    
\end{document}

相關內容