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

hyphen or minus symbol breaks \cite in texcomments #312

Open
nachsommer opened this issue Nov 8, 2021 · 2 comments
Open

hyphen or minus symbol breaks \cite in texcomments #312

nachsommer opened this issue Nov 8, 2021 · 2 comments

Comments

@nachsommer
Copy link

If you want to cite something (via biber and biblatex) in the source code's commentaries, the \cite-command works fine:


\begin{minted}[escapeinside=||,texcomments]{java} 
    public int getRandomInt(int max) {
    
        /* This method selects a pseudo-random integer, 
          though computers don't do well with truly randomness \parencite{rubin:2011}.
         */
        int min = 1;

        // \emph{JAVA} can, however, create a pseudo random Integer by:
        Random randomInt = new Random();
        // Unfortunately, this is not serendipity \parencite{mccay-peet+toms:2017}
        return randomInt.nextInt(max - min) + min;
    }
\end{minted}

The first citation (rubin:2011) works well, the second however breaks due the "-" in the keyword "mccay-peet+toms:2017". The result in the comment shows something like this:

(mccay\unhbox \voidb@x \kern \z@ \char ‘\-peet+toms:2017)

Can anyone help with a workaround? Thanks a lot!

@muzimuzhi
Copy link
Contributor

A catcode issue. For a quick workaround, you can define a macro storing cite keys containing - and use \parencite{\macro} in minted.

\documentclass{article}
\usepackage{minted}

\begin{document}
\cite{rubin:2011} and \cite{mccay-peet+toms:2017}

\def\mycite{mccay-peet+toms:2017}
\begin{minted}[escapeinside=||,texcomments]{java} 
    public int getRandomInt(int max) {
    
        /* This method selects a pseudo-random integer, 
          though computers don't do well with truly randomness \cite{rubin:2011}.
         */
        int min = 1;

        // \emph{JAVA} can, however, create a pseudo random Integer by:
        Random randomInt = new Random();
        // Unfortunately, this is not serendipity \cite{\mycite}
        return randomInt.nextInt(max - min) + min;
    }
\end{minted}

\begin{thebibliography}{00}
  \bibitem{rubin:2011}
  \bibitem{mccay-peet+toms:2017}
\end{thebibliography}
\end{document}

@muzimuzhi
Copy link
Contributor

Seems it's fvextra that makes - active (with catcode 13). Also I find \cite{\detokenize{mccay-peet+toms:2017}} works as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants