Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referring to other packages when using tcolorbox/documentation #290

Open
mikkelee opened this issue Sep 12, 2024 · 11 comments
Open

Referring to other packages when using tcolorbox/documentation #290

mikkelee opened this issue Sep 12, 2024 · 11 comments
Assignees

Comments

@mikkelee
Copy link

mikkelee commented Sep 12, 2024

I'm writing docs for one of my packages & have found a need to refer to other packages. I don't see a standard way of doing this in the tcolorbox documentation section, so I cooked up the below by copying the reference format from tcbdocumentation.code.tex line 915. Perhaps others find it useful:

\makeatletter
\newcommand\refPkg[1]{%
  \href{https://ctan.org/pkg/#1}{%
    \refAux{#1}%
    \kvtcb@doc@format@page{{\fontfamily{pzd}\fontencoding{U}\fontseries{m}\fontshape{n}\selectfont\char213}%
    \,CTAN}%
  }%
}
\makeatother

Example usage: The box can be further configured via \docAuxCommand*{tcbset} as per the \refPkg{tcolorbox} documentation. will create a href pointing to https://ctan.org/pkg/tcolorbox that looks like this:

Screenshot 2024-09-12 at 20 08 19
@mikkelee mikkelee changed the title Referring to other packages from tcolorbox/documentation Referring to other packages when using tcolorbox/documentation Sep 12, 2024
@muzimuzhi
Copy link
Contributor

Nice extension!

Just to remind that for some LaTeX packages (<latex-pkg>.sty files), their CTAN names are not directly <latex-pkg>. See a list of mapping here (not sure if comprehensive).

@mikkelee
Copy link
Author

mikkelee commented Sep 13, 2024

Thanks :)

Perhaps an optional argument:

\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{documentation}

\makeatletter
\NewDocumentCommand \refPkg { o m } {%
  \IfValueTF{#1}{%
    \href{https://ctan.org/pkg/#1}%
  }{%
    \href{https://ctan.org/pkg/#2}%
  }{%
    \refAux{#2}%
    \kvtcb@doc@format@page{{\fontfamily{pzd}\fontencoding{U}\fontseries{m}\fontshape{n}\selectfont\char213}% from tcbdocumentation.code.tex line 915
    \,CTAN}%
  }%
}
\makeatother

\begin{document}

The box can be further configured via \docAuxCommand*{tcbset} as per the \refPkg{tcolorbox} documentation.

Linking to a .sty file in a differently named CTAN distribution: \refPkg[preprint]{fullpage}.

\end{document}

e: oh, I guess this one actually has ctan pages for the sub-packages (picked it randomly from the json doc): https://ctan.org/pkg/fullpage

@muzimuzhi
Copy link
Contributor

Tip: In \NewDocumentCommand,

The default for O, D and E arguments can be the result of grabbing another argument.

texdoc usrguide (2024-05-24), sec. 2.5 Optional Arguments

so the definition of \refPkg can be simplified to

\makeatletter
\NewDocumentCommand \refPkg { O{#2} m } {%
  \href{https://ctan.org/pkg/#1}%
  {%
    \refAux{#2}%
    \kvtcb@doc@format@page{{\fontfamily{pzd}\fontencoding{U}\fontseries{m}\fontshape{n}\selectfont\char213}% from tcbdocumentation.code.tex line 915
    \,CTAN}%
  }%
}
\makeatother

@mikkelee
Copy link
Author

Oh nice, that's good to know!

@T-F-S
Copy link
Owner

T-F-S commented Sep 18, 2024

I like this addition very much and I will integrate it as is into the next version. Thank you 👍

@T-F-S T-F-S self-assigned this Sep 18, 2024
@mikkelee
Copy link
Author

Thanks to you as well, looking forward to it :)

@T-F-S
Copy link
Owner

T-F-S commented Sep 27, 2024

Done with https://github.com/T-F-S/tcolorbox/releases/tag/v6.4.0

@T-F-S T-F-S closed this as completed Sep 27, 2024
@muzimuzhi
Copy link
Contributor

muzimuzhi commented Nov 27, 2024

It seems to me that the "CTAN" in small size (in Computer Modern/Latin Modern Roman) doesn't look very well (see for instance #302 (comment)), maybe \texttt{CTAN} or \textsf{CTAN} can improve readability a bit.

image
Example used to produce the screenshot above

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{documentation}
\hypersetup{colorlinks}

\makeatletter
\RenewDocumentCommand \refPkg { O{#2} m } {%
  \href{https://ctan.org/pkg/#1}%
  {%
    \refAux{#2}%
    \kvtcb@doc@format@page{{\fontfamily{pzd}\fontencoding{U}\fontseries{m}\fontshape{n}\selectfont\char213}%
    \,\formatCTAN{CTAN}}%
  }%
}
\makeatother

\NewDocumentCommand{\formatCTAN}{m}{#1}

\begin{document}
rmfamily \refPkg{tcolorbox}

\let\formatCTAN=\texttt
ttfamily \refPkg{tcolorbox}

\let\formatCTAN=\textsf
sffamily \refPkg{tcolorbox}
\end{document}

@dbitouze
Copy link
Contributor

@muzimuzhi I guess it is in small caps, not in small size.

@muzimuzhi
Copy link
Contributor

@dbitouze It's controlled by /tcb/page ref formatter whose initial value is \textsuperscript, so "CTAN" has the baseline and size of script math. Redefining \refPkg to using lowercase letters then the page ref shows lowercase letters, so it's not in small caps.

@T-F-S
Copy link
Owner

T-F-S commented Nov 29, 2024

Beauty is in the eye of the beholder... I will add a customization for formatting the CTAN string in the next version:

grafik

@T-F-S T-F-S reopened this Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants