1

Due to issues with Minted's escapeinside option, I would like to include, but completely hide (without taking up any space), a minted environment within my document. I do not want any of the content to be visible.

I've gotten pretty close with this hacky solution, which uses a tiny font size:

\begin{minted}[fontsize=\fontsize{0.01pt}{0.01pt}]{java}
public String someCode(String argument) {
    // code here...
}
\end{minted}

Is there a more elegant solution than just using a very small font size? Can I put it inside some sort of box, and set it to have a zero height? Can I float it somehow, such that it never gets actually shown anywhere in the document?

It's important that the code is actually processed. I therefore can't just comment it out, or use a \if.

1

We define a savebox with \newsavebox.

It's possible to then create an lrbox environment (specifying the savebox name), and throw the minted code listing inside a minipage.

\newsavebox\hideminted

\begin{lrbox}{\hideminted}\begin{minipage}{\textwidth}
\begin{minted}[fontsize=\fontsize{0.01pt}{0.01pt}]{java}
public String lookupUserNameByToken(String token) throws SQLException {
    Statement stmt = connection.createStatement();
    String query = "select * from users where ";
    query += "token = '" + token + "'";
    ResultSet rs = stmt.executeQuery(sql);
    if (rs.next()) {
        return rs.getString("name");
    }
    return null;
}
\end{minted}
\end{minipage}\end{lrbox}

We then ensure that we never \usebox{\hideminted}, and it will never actually appear in the document.

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.