4

The new ACM template has introduces new environments like 'example', 'definition', etc. Now you can write:

\begin{example}
\label{myex}
Assume BLA BLA
\end{example}

and the output should be:

Example 4.1 Assume BLA BLA

But if you use \cref{myex} to cross-reference it, that would appear with 'theorem' label instead of 'example':

In \cref{myex}, we explained BLA BLA

the output is:

In theorem 4.1. we explained BLA BLA

I don't want to modify the main .cls file, instead I'm trying to renew comments or so. I tried a few tricks including this but didn't work out.

Update:

The minimum compilable code:

\documentclass[sigconf]{acmart}
\usepackage{cleveref}

\Crefname{example}{Example}{Examples}

\begin{document}
\begin{example}
\label{myex}
Assume bla bla
\end{example}

In \cref{myex}, we show 
\end{document}
  • 1
    Normally \crefname{example}{Example}{Examples} should work (and is setup by default by cleveref already,most likely), but perhaps the theorem environments use counter names that do not match the environment. Please provide a compilable example instead of your fragments only – user31729 Mar 30 '17 at 14:12
  • 1
    Of course I meant \Crefname above, for the upper - case names – user31729 Mar 30 '17 at 14:19
  • 1
    "The new ACM template..." -- For the uninitiated, would you mind stating what the template is called and where it might be obtained from? – Mico Mar 30 '17 at 14:22
  • 1
    @Farzad: No, use \Cref{myex} or say \crefname{example}{example}{examples} in addition to \Crefname` (like in your post), you can use \cref{example} – user31729 Mar 30 '17 at 15:25
  • 1
    @Farzad: Did you recompile twice? For me it works! – user31729 Mar 30 '17 at 15:38
4

Solution [suggested by christian-hupfer]:

Specify the counter that you wish to use, by overruling it while using the \label. Like this:

\label[example]{myex}

Similarly, if you are using another environment (e.g. 'definition') you can overrule the counter like this:

\label[definition]{mydef}
2

I suggest you do the following:

  • Find the file acmart.cls in your TeX distribution. (In MacTeX2016, which is the TeX distribution on my system, the file is located at /usr/local/texlive/2016/texmf-dist/tex/latex/acmart/acmart.cls.)

  • Make the copy of this file, and call the copy (say) acmartclever.cls. Do not edit or otherwise modify the file acmart.cls directly.

  • Open the file acmartclever.cls in a text editor. (The editor you use for your tex files will do fine.)

  • Do a global search-and-replace on the string acmart.cls -- there should be 11 instances of this string -- and replace this string with acmartclever.cls.

  • On line 40 of the file, replace the string \ProvidesClass{acmart} with \ProvidesClass{acmartclever}.

    Similarly, on line 43 of the file, replace the string \def\@classname{acmart} with \def\@classname{acmartclever}.

  • Go to line 2188 of the file and insert the instruction

    \usepackage{cleveref}
    

    immediately ahead of the line that says \theoremstyle{acmplain}. Why not later in the file, you may ask? It's because that what follows the \theoremstyle{acmplain} declaration is the group of definitions of a long list of theorem-like environments, such as theorem, conjecture, proposition, lemma, corollary, example, and definition. cleveref is clever enough to associate environments with labels even if all theorem-like environments share the same counter. However, in order to perform these clever associations, cleveref must be loaded before the theorem-like environments are set up.

    If you're in the habit of loading cleveref with some or all of the options nameinlink, capitalize, and noabbrev, you should either specify them now, i.e., write something like

    \usepackage[nameinlink,capitalize,noabbrev]{cleveref}
    

    Alternatively, and rather more flexibly, just provide some or all of these options in the list of options you specify in the \documentclass instruction.

  • Save the file acmartclever.cls in the directory where your main tex file is located.

  • In your main tex file, the first line should now read

    \documentclass[<options>]{acmartnew}
    

Happy TeXing!


A full MWE:

enter image description here

\documentclass[sigconf,capitalize]{acmartclever} % note the option 'capitalize': it will
                                                 % be passed to 'cleveref'
\begin{document}
\setcounter{section}{2} % just for this example

\begin{example}\label{myex}
Assume bla bla
\end{example}

In \cref{myex}, we showed that \dots
\end{document}
  • Ideally, in some future revision of the acmart document class, an option will be provided to load the cleveref package directly, possibly via a suitable option that may be specified at the \documentclass[<options>]{cleveref} stage. – Mico Mar 31 '17 at 19:42
2

I've added cleveref to the list of packages used. After this version becomes official the problem is resolved

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.