0

I'm sure a lot of people asked this already, but I'm not able to find the correct answer.

I want to keep track of my label/keys that I was giving a tcbtheorem. I don't know the best practise to encounter this problem I would like to have a section or chapter somewhere in my document but I would be also happy with the label/key in the margin section of the pdf.

I saw the idea, that is good to have the label/key in the margin section of the pdf.

But when I tried to solve like that I did get the expected result when I used \label{} (see the provided code below)

Also

% Command to automatically display the reference
\newcommand{\autoNameref}[1]{\nameref{def:#1}}

\begin{document} \tcblistof[\section*]{def}{List of Defenition}

works fine.

But I can't see the given references of def:Pi or def:TestRef in the margin section or somewhere else. If I \label it like that:

{for example Pi\label{def:Pi2}}

This goes the wrong direction I would say, why I should \label everything when I did all the previus effort.

Maybe I have to

\usepackage{nameref} 
\usepackage{showkeys}
\usepackage{showexpl}

start this in a different way but I don't find any information about that. I also searched a lot of time in the tcolorbox - manual: tcolorbox - manual

I would appreciate any hints or solutions.

Thank you for your help.

I tried to shorten my preamble as much I was sure it would be ok.

The following code:

should resolve in this PDF

\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}

\usepackage{nameref} \usepackage{showkeys} \usepackage{showexpl} % Math packages + Access additional mathematical symbols \usepackage{amsmath,amsfonts,amsthm,amssymb,mathtools}

% Hyperlinks and PDF properties \usepackage{hyperref,theoremref}

% Colored boxes and tcolorbox configurations \usepackage[most,many,breakable]{tcolorbox}
% Libraries for diagrams and plots \usepackage{tikz-cd} \usepackage{pgfplots}

\usetikzlibrary{ % tcolorbox some boxes arrows, calc, shadows.blur}

% Conditional commands \usepackage{xparse} % Dummy text generator \usepackage{lipsum} % For generating placeholder text % store a big set of sentences \unpacklipsum[1-100]

\ExplSyntaxOn % unpack \lipsumexp \seq_new:N \g_lipsum_sentences_seq \cs_generate_variant:Nn \seq_set_split:Nnn { NnV } \seq_gset_split:NnV \g_lipsum_sentences_seq {.~} \lipsumexp

\NewDocumentCommand{\lipsumsentence}{>{\SplitArgument{1}{-}}O{1-7}} { \lipsumsentenceaux #1 } \NewDocumentCommand{\lipsumsentenceaux}{mm} { \IfNoValueTF { #2 } { \seq_item:Nn \g_lipsum_sentences_seq { #1 }.~ } { \int_step_inline:nnnn { #1 } { 1 } { #2 } { \seq_item:Nn \g_lipsum_sentences_seq { ##1 }.~ } } } \ExplSyntaxOff

\setlength{\parindent}{1cm}

\tcbset{ BandarolGroundStyle/.style={ attach boxed title to top left={xshift=1cm,yshift=1mm-\tcboxedtitleheight}, varwidth boxed title=-3cm, boxed title style={frame code={ \path[fill=tcbcolback] ([yshift=-1mm,xshift=-1mm]frame.north west) arc[start angle=0,end angle=180,radius=1mm] ([yshift=-1mm,xshift=1mm]frame.north east) arc[start angle=180,end angle=0,radius=1mm]; \path[left color=tcbcolback!60!black,right color=tcbcolback!60!black, middle color=tcbcolback!80!black] ([xshift=-2mm]frame.north west) -- ([xshift=2mm]frame.north east) [rounded corners=1mm]-- ([xshift=1mm,yshift=-1mm]frame.north east) -- (frame.south east) -- (frame.south west) -- ([xshift=-1mm,yshift=-1mm]frame.north west) [sharp corners]-- cycle; } ,interior engine=empty }, fonttitle=\bfseries, label separator=: }, defstyle/.style={ enhanced, before skip=2mm, after skip=2mm, colback= #1!5, colframe= #1!80!black, colbacktitle= #1!75!black, boxrule=0.5mm, BandarolGroundStyle } }

%================================ % DEFINITION BANDAROLLED THEOREMS %================================ % list inside={def} maybe a good idea but check it later % \tcblistof[\section*]{def}{List of Defenition} \newtcbtheorem[number within=section, list inside={def}]{Definition}{Definition}{defstyle=red, title={#2},#1}{def}

%================================ % xparse commands for theorems: %================================ % reason: % https://tex.stackexchange.com/questions/48355/latex-command-with-optional-arguments % It is also possible to use optional Arguments: % r = required Argument % o = optional Argument % O = optional Argument if empty default value

% Order of the Attributes (Ref, Titel, Body) % not working because of \MainAttributes in command... % \newcommand\MainAttributes{O +m +m} % Order so it is correct with the newtcbtheorem initialisation % not working because of \MainOrder in command... % \edef\MainOrder{{#2}{#1}#3} % solutions: % https://tex.stackexchange.com/questions/551429/how-to-use-newdocumentcommand % https://tex.stackexchange.com/questions/139614/you-cant-use-macro-parameter-character-in-restricted-horizontal-mode % https://tex.stackexchange.com/questions/393622/using-key-values-in-newdocumentcommand

% to less time maybe a revisit later...

%================================ % DEFINITION BANDAROLLED THEOREMS %================================

\NewDocumentCommand {\dfn} {O +m +m}{ \begin{Definition}{#2}{#1}#3 \end{Definition}}

% Customize the format for displaying keys and labels \renewcommand*\showkeyslabelformat[1]{\normalfont\small\ttfamily#1}

% Command to automatically display the reference \newcommand{\autoNameref}[1]{\nameref{def:#1}}

\begin{document} \tcblistof[\section*]{def}{List of Defenition} \label{test} \lipsum[1]

\dfn[Pi]{A defined Number }{for example Pi}

\lipsum[2]

\nameref{def:Pi} \ref{def:Pi}

\begin{LTXexample}[pos=r, width=0.5\linewidth] \dfn[TestRef]{RefTest}{TextRefTest} \end{LTXexample}

\end{document}

NikT
  • 3

1 Answers1

0

Well the label is there, but it is hidden behind the title of the tcolorbox as for some reason showkeys uses a \rlap. You can move it into the margin:

\documentclass[12pt,a4paper]{book}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{showkeys}
\usepackage{hyperref}
\usepackage[most,many,breakable]{tcolorbox}

\newtcbtheorem[number within=section, list inside={def}] {Definition}{Definition}{ frame empty,coltitle=red, %to remove the background title={#2},#1}{def}

\begin{document} \section{A}\label{test} \section{B}\label{longertest}

\begin{Definition}{A defined Number }{Pi} for example Pi \end{Definition}

\renewcommand*\showkeyslabelformat[1] {% \normalfont\small\ttfamily \llap{\fbox{#1}\hspace{\marginparsep}}% }

\begin{Definition}{A defined Number }{ratio} for example the golden ratio \end{Definition}

\ref{test}, \ref{def:Pi}

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • Thank you very much. You saved my mental health. ;) I upvoted your answer, but my reputation is to low. – NikT Jan 03 '24 at 19:01