0

My question is a follow up of Cryptocode: Cref should link to a game, and write its name : so far, in a memoir document I display some "figures" (typically in a new float environment) representing a cryptographic game:

enter image description here

As the name of the game is already written at the top of the box, I don't want to put any caption. However, I still want to be able to provide the list of all games, using for instance the \listof{floatGame}{List of Games} command provided by the float package.

How could I make sure that the name of the game is printed in the table of content, without adding a visible caption?

enter image description here

MWE:

\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}

tobiasBora
  • 8,684
  • 1
    My idea would be not to use the figure environment for the table of games but to follow the idea given here: https://tex.stackexchange.com/questions/77992/a-list-of-all-the-labelled-sentences?noredirect=1&lq=1 – Harald Lichtenstein Feb 01 '22 at 21:55
  • @HaraldLichtenstein, thanks, it works great! – tobiasBora Feb 02 '22 at 09:46

1 Answers1

1

As pointed out by Harald Lichtenstein, this question works (I heard that some tocloft packages was not compatible with memoir, but the above answer works also in memoir): the command \@starttoc{game} displays the toc (make sure to use \makeatletter...\makeatother around it), and \addcontentsline{game}{section}{#4} adds something in the toc.

\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}

EDIT

In the memoir class, you can replace the line \NewDocumentDommand\listofgames... with:

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

it will avoid starting the chapter on a new double page. However, I'm curious to know how it manages to start a chapter without creating a new page... If anyone knows, I'm interested!

EDIT

Actually, I checked and I found a way to start a chapter on a non-right page using \openany... and one can also redefine \def\clearforchapter{...} to start a chapter on without creating a new page.

tobiasBora
  • 8,684
  • 1
    Functionality similar to tocloft is build directly into memoir (mostly they are name the same way, but not always) – daleif Feb 02 '22 at 10:13
  • @daleif ok, good to know, thanks! Btw, I added "\chapter*{List of games}" to add the title of the table of contents, but it is pushed on a page starting on the right page. On the other side, \listoffigures starts a chapter that does not even need to start a new page (I need to manually add it). Any idea how \listoffigures manages to use the style of chapter without creating a new page? – tobiasBora Feb 02 '22 at 10:25
  • I managed to find a solution (see my edit), but I'm curious to understand how it works internally: I can't find any way to create myself a chapter that won't create a new page. – tobiasBora Feb 02 '22 at 10:37
  • 1
    \tableofcontents and friends uses the chapter interface to typeset their titles, but not \chapter* or equivalent. They do not force a page break since if you only have a few tables and figures, you might want to have the list of tables and list of figures on the same page. Technically they define \Xheadstart, \afterXtitle, \printXnonum and \printXtitle which are initialised to their X=chapter equivalents. And they always use page style chapter. – daleif Feb 02 '22 at 10:43
  • @daleif cool, thanks a lot! Actually, I checked and I found a way to start a chapter on a non-right page using \openany... and one can also redefine \def\clearforchapter{...} to start a chapter on without creating a new page :D – tobiasBora Feb 02 '22 at 10:49
  • That is not a good idea. What is your reasoning you you to need a chapter that does not start a new page? – daleif Feb 02 '22 at 11:03
  • @daleif similarly, to create a small section in the frontmatter, maybe a "notation" page, or something similar. And for curiosity ^^' – tobiasBora Feb 02 '22 at 11:34