LaTeX:使浮动出现在“列表”中而不显示任何标签

LaTeX:使浮动出现在“列表”中而不显示任何标签

我的问题是加密代码:Cref 应该链接到一个游戏,并写上它的名字:到目前为止,memoir我在文档中展示了一些代表加密游戏的“图形”(通常在新浮动环境中):

在此处输入图片描述

由于游戏名称已经写在框顶部,我不想添加任何标题。但是,我仍然希望能够提供所有游戏的列表,例如使用包\listof{floatGame}{List of Games}提供的命令float

我如何确保游戏名称打印在目录中,而无需添加可见的标题?

在此处输入图片描述

梅威瑟:

\documentclass[]{article}

\usepackage{amsmath}
\usepackage [
n,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{gameProc}{center,boxed}{}{}{}
\usepackage{lipsum}
\usepackage{float}

\newfloat{floatGame}{htb!}{Game}
\floatname{floatGame}{Game}

\makeatletter
% Usage: \begin{mygame}[label][short title]{title} content \end{mygame}
\NewDocumentEnvironment{game}{soomb}{%
  \IfBooleanTF{#1}{\begin{floatGame}[htbp]}{\begin{floatGame}[H]}%
      \caption{#4}%
      \begin{pcimage}%
        {\normalfont\gameProc[linenumbering]{#4}{\IfValueTF{#2}{%
              %% Add an anchor if a label is present
              \raisebox{1em}{\hypertarget{#2}{}}%
              %% Create a macro "mygametitle@nameoflabel" to store the title
              \IfValueTF{#3}{% If a short title is provided
                \expandafter\gdef\csname mygametitle@#2 \endcsname{#3}%%
                \write\@auxout{\gdef\string\mygametitle@#2{#3}}%
              }{%
                \expandafter\gdef\csname mygametitle@#2 \endcsname{#4}%%
                \write\@auxout{\gdef\string\mygametitle@#2{#4}}%
              }%
            }{} #5 }}%
      \end{pcimage}
    \end{floatGame}%
  }{}
  
% Usage: \refGame{label}
\NewDocumentCommand{\refGame}{m}{%
  \hyperlink{#1}{\csname mygametitle@#1\endcsname}% Do not put a white space after #1!
}

\makeatother

\definecolor{secondaryColor}{RGB}{206,149,0} %% darker orange, looks like gold. <3
\usepackage[
  colorlinks,
  allcolors=secondaryColor % https://tex.stackexchange.com/a/50754/
]{hyperref}

%\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\listof{floatGame}{List of Games}

\section{Content}

I provide a new environment \verb|game|, where you can specify an optional star (to insert it into a floating figure), an optional label (\textbf{WARNING: do not use any number in the label}) if you want to refer to it later, an optional short title (used when citing the game), the real title, and finally the content.
\begin{game}*[myGreatGame][$\indcpa$]{$\indcpa_\enc^\adv(\secpar)$}
  b \sample \bin  \\
  (\pk,\sk) \sample \kgen (\secparam)  \\
  (\state,m_0,m_1) \sample \adv(\secparam, \pk, c)   \\
  c \sample \enc(\pk,m_b)  \\
  b' \sample \adv(\secparam, \pk, c, \state) \\
  \pcreturn b = b'
\end{game}

You can then refer to the game using \verb|refGame|, like \refGame{myGreatGame}.

\end{document}

答案1

正如 Harald Lichtenstein 所指出的,这个问题作品(我听说有些 tocloft 包与 不兼容memoir,但上述答案在 中也有效memoir):该命令\@starttoc{game}显示目录(确保\makeatletter...\makeatother在其周围使用),并\addcontentsline{game}{section}{#4}在目录中添加一些内容。

\documentclass[]{memoir}

\usepackage{amsmath}
\usepackage [
n,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{gameProc}{center,boxed}{}{}{}
\usepackage{lipsum}
\usepackage{float}

\newfloat{floatGame}{htb!}{Game}
\floatname{floatGame}{Game}

\makeatletter

\NewDocumentCommand\listofgames{O{List of Games}}{\chapter{List of Games}\@starttoc{game}}

% Usage: \begin{mygame}[label][short title]{title} content \end{mygame}
% Première Etoile: dans un float
% Deuxième étoile: n'ajoute pas dans la table of contents.
\NewDocumentEnvironment{game}{soomsb}{%
  \IfBooleanTF{#1}{\begin{floatGame}[htbp]}{}%
      \begin{pcimage}%
        \phantomsection\IfBooleanTF{#5}{}{\addcontentsline{game}{section}{#4}} %
        {\normalfont\gameProc[linenumbering]{#4}{\IfValueTF{#2}{%
              %% Add an anchor if a label is present
              \raisebox{1em}{\hypertarget{#2}{}}%
              %% Create a macro "mygametitle@nameoflabel" to store the title
              \IfValueTF{#3}{% If a short title is provided
                \expandafter\gdef\csname mygametitle@#2 \endcsname{#3}%%
                \write\@auxout{\gdef\string\mygametitle@#2{#3}}%
              }{%
                \expandafter\gdef\csname mygametitle@#2 \endcsname{#4}%%
                \write\@auxout{\gdef\string\mygametitle@#2{#4}}%
              }%
            }{} #6 }}%
      \end{pcimage}
    \IfBooleanTF{#1}{\end{floatGame}}{}%
  }{}

  
% Usage: \refGame{label}
\NewDocumentCommand{\refGame}{m}{%
  \hyperlink{#1}{\csname mygametitle@#1\endcsname}% Do not put a white space after #1!
}

\makeatother

\definecolor{secondaryColor}{RGB}{206,149,0} %% darker orange, looks like gold. <3
\usepackage[
  colorlinks,
  allcolors=secondaryColor % https://tex.stackexchange.com/a/50754/
]{hyperref}

%\usepackage{hyperref}
\usepackage{cleveref}

\begin{document}

\listofgames

\chapter{Content}

I provide a new environment \verb|game|, where you can specify an optional star (to insert it into a floating figure), an optional label (\textbf{WARNING: do not use any number in the label}) if you want to refer to it later, an optional short title (used when citing the game), the real title, and finally the content.
\begin{game}[myGreatGame][$\indcpa$]{$\indcpa_\enc^\adv(\secpar)$}
  b \sample \bin  \\
  (\pk,\sk) \sample \kgen (\secparam)  \\
  (\state,m_0,m_1) \sample \adv(\secparam, \pk, c)   \\
  c \sample \enc(\pk,m_b)  \\
  b' \sample \adv(\secparam, \pk, c, \state) \\
  \pcreturn b = b'
\end{game}

\begin{game}*[$blabla$]{$bleble$}*
  I should not be included .
\end{game}

You can then refer to the game using \verb|refGame|, like \refGame{myGreatGame}.

\end{document}

编辑

在回忆录课中,你可以将这一行替换\NewDocumentDommand\listofgames...为:

\newlistof{listofgames}{game}{List of figures}

它将避免在新的双页上开始章节。但是,我很好奇它是如何做到在不创建新页面的情况下开始章节的......如果有人知道,我很感兴趣!

编辑

实际上,我检查了一下,发现了一种使用 \openany... 在非正确页面上开始章节的方法,并且还可以重新定义 \def\clearforchapter{...} 以开始章节而不创建新页面。

相关内容