Code Monkey home page Code Monkey logo

Comments (5)

gpoore avatar gpoore commented on August 19, 2024

Can you give an example that will produce this?

from minted.

AndreyAkinshin avatar AndreyAkinshin commented on August 19, 2024

Try this:

\usepackage{minted}
\newmintinline[csharpcode]{csharp}{}
\newcommand{\code}[1]{\csharpcode{#1}}

\begin{document}
\code{var a = "Line1\nLine2";}
\end{document}

I have a space before the '2' symbol.

from minted.

gpoore avatar gpoore commented on August 19, 2024

You want something like

\newcommand{\code}{\csharpcode}

or

\newmintinline[code]{csharp}{}

The macro you created captured its argument, and then passed it on to \csharpcode. Since the macro was created with the standard \newcommand, LaTeX assumed that it was capturing valid LaTeX code. Since \nLine looks like a macro to LaTeX, it must be inserting a space after it during capture. What you want to do is make sure that the commands defined by minted always do the capturing, because they are specially designed to capture arguments exactly verbatim.

from minted.

AndreyAkinshin avatar AndreyAkinshin commented on August 19, 2024

In this case, I have troubles with probsoln packages. My code:

\usepackage{probsoln}
\setkeys{probsoln}{fragile}
\usepackage{minted}
\newmintinline[csharpcode]{csharp}{}
\newcommand{\code}[1]{\csharpcode{#1}}

\begin{document}
\begin{defproblem}{MyProblem}
\code{@"\" + "\n"}
\end{defproblem}
\foreachproblem{\thisproblem}
\end{document}

How I can improve it?

from minted.

gpoore avatar gpoore commented on August 19, 2024

I suspect that probsoln has a bug with its fragile mode. It is writing environment contents to a *.vrb file, but the environment contents aren't really written verbatim; there's a space inserted after everything that looks like a macro, including \n.

Probably the simplest thing to do is use a savebox as a workaround.

\documentclass{article}

\usepackage{probsoln}
\setkeys{probsoln}{fragile}
\usepackage{minted}
\newmintinline[csharpcode]{csharp}{}
\newcommand{\code}{\csharpcode}

\begin{document}

\newsavebox\mybox
\begin{lrbox}{\mybox}
\code{@"\" + "\n"}
\end{lrbox}

\begin{defproblem}{MyProblem}[fragile]
\usebox{\mybox}
\end{defproblem}
\foreachproblem{\thisproblem}
\end{document}

from minted.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.