0

I have next problem:

I can't compile code after I copied and paste it in editor, because dashes on the left side of picture are not the same as on the right.

enter image description here

but if I replace "−" to "−" it will work fine (surprisingly, dashes were pasted here are both correct) here You can find main source https://github.com/AnMnv/eBook (page 9)

Couse to paste here MWE is just useless, because all dashed pasted correctly on this site, so I would be very grateful if You can follow the link above open eBook.pdf and try to copy example 4.10 from page 9 into Your editor.

And if You want to see the error message: enter image description here

MWE:

\documentclass{article}

\usepackage{scrextend} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[russian,english]{babel} \usepackage[table]{xcolor} \usepackage{nicematrix} \NiceMatrixOptions{cell-space-top-limit=5pt,cell-space-bottom-limit=5pt}

\usepackage{listings} \lstset{ basicstyle=\ttfamily, columns=fullflexible, frame=single, breaklines=true, postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space}, }

\newcommand\realnumberstyle[1]{}

\makeatletter \newcommand{\zebra}[3]{% {\realnumberstyle{#3}}% \begingroup \lst@basicstyle \ifodd\value{lstnumber}% \color{#1}% \else \color{#2}% \fi \rlap{\hspace*{\lst@numbersep}% \color@block{\linewidth}{\ht\strutbox}{\dp\strutbox}% }% \endgroup } \makeatother

\begin{document}

\begin{tabular}{c | c} \begin{minipage}[m]{0.4\textwidth} \begin{NiceTabular}{|c|c|c|} \hline \cellcolor{red}1& \cellcolor{green}1 & \cellcolor{black!10}EVERY\\hline \cellcolor{orange}1 & \cellcolor{red!35}1 & \cellcolor{brown!50}CELL \ \hline \cellcolor{green!35}1 & \cellcolor{blue!45}1 & \cellcolor{yellow}CENTERED \ \hline \end{NiceTabular} \end{minipage} & \begin{minipage}[m]{0.55\textwidth} \begin{lstlisting}[numberstyle=\zebra{green!15}{yellow!15},numbers=left,basicstyle=\footnotesize] \documentclass{article} \usepackage[table]{xcolor} \usepackage{nicematrix} \NiceMatrixOptions{cell-space-top-limit=5pt,cell-space-bottom-limit=5pt}

\begin{document} \begin{table}[htbp] \centering \begin{NiceTabular}{|c|c|c|} \hline \cellcolor{red}1& \cellcolor{green}1 & \cellcolor{black!10}1 \ \hline \cellcolor{orange}1 & \cellcolor{red!35}1 & \cellcolor{brown!50}1 \ \hline \cellcolor{green!35}1 & \cellcolor{blue!45}1 & \cellcolor{yellow}1 \ \hline \end{NiceTabular} \end{table} \end{document} \end{lstlisting} \end{minipage} \end{tabular}

\end{document}

Thanks in advance.

David Carlisle
  • 757,742
WinnieNotThePooh
  • 3,008
  • 1
  • 7
  • 14
  • 1
    please dont post code and error messages as image that makes it impossible to debug, and don't use external links that will change over time, post a small example here that generates the error. – David Carlisle Dec 20 '21 at 21:45
  • I can't say anything about your images, but in your text but if I replace "−" to "−" both dashes are minus signs U+2212 not the ascii hyphen - that you need in key names – David Carlisle Dec 20 '21 at 21:48
  • Sorry, @DavidCarlisle but as I said "here MWE is just useless, because all dashed pasted correctly on this site" And the problem is when I copyed from .pdf and it pasted not like minus but like You said "acii hyphen" or something like that and my code cant be compiled cose of it (and about issue: it is also useless to post it in text couse there is nothink to debug) – WinnieNotThePooh Dec 20 '21 at 21:57
  • with no posted example I'm not going to debug but the pdf clearly shows minus signs, did you typeset the key names in math mode? – David Carlisle Dec 20 '21 at 21:57
  • no it would not be useless at all, the one bit of text you pasted to this site but if I replace "−" to "−" already shows the problem, they are minus signs, −, not hyphens, - and the problem is unrelated to cut and paste as it is clearly visible in your pdf output. the listings or minted or whatever you are using to typeset the code is typesetting a key aaa-bbb as aaa−bbb presumably as it is misusing math mode somewhere so you could make a small complete test file that typesets one latex code listing using keys of that form that we can debug, – David Carlisle Dec 20 '21 at 22:00
  • I think no, didnt typeset the key names in math mode? (to say the truth I even do not understand what are You talking about) – WinnieNotThePooh Dec 20 '21 at 22:01
  • if you typeset a-b in text mode you will get a hyphen that will cut and paste as - if you typeset a-b in math mode you will get a minus sign that probably cuts and pastes as − if you provided an example someone would say why you are getting minus signs in your output. – David Carlisle Dec 20 '21 at 22:03
  • oook, I understand You I'll post full MWE for debug in a minute – WinnieNotThePooh Dec 20 '21 at 22:03
  • 5

1 Answers1

0

listings uses \textminus a minus sign for - I couldn't see how to stop it doing that easily using the key=value interface, but you can locally redefine \textminus to be an ASCII - so it works in code:

enter image description here

Just adds the one marked definition.

\documentclass{article}

\usepackage{scrextend} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[russian,english]{babel} \usepackage[table]{xcolor} \usepackage{nicematrix} \NiceMatrixOptions{cell-space-top-limit=5pt,cell-space-bottom-limit=5pt}

\usepackage{listings} \lstset{ basicstyle=\ttfamily, columns=fullflexible, frame=single, breaklines=true, postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space}, }

\newcommand\realnumberstyle[1]{}

\makeatletter \newcommand{\zebra}[3]{% {\realnumberstyle{#3}}% \begingroup \lst@basicstyle \ifodd\value{lstnumber}% \color{#1}% \else \color{#2}% \fi \rlap{\hspace*{\lst@numbersep}% \color@block{\linewidth}{\ht\strutbox}{\dp\strutbox}% }% \endgroup } \makeatother

\begin{document}

\begin{tabular}{c | c} \begin{minipage}[m]{0.4\textwidth} \begin{NiceTabular}{|c|c|c|} \hline \cellcolor{red}1& \cellcolor{green}1 & \cellcolor{black!10}EVERY\\hline \cellcolor{orange}1 & \cellcolor{red!35}1 & \cellcolor{brown!50}CELL \ \hline \cellcolor{green!35}1 & \cellcolor{blue!45}1 & \cellcolor{yellow}CENTERED \ \hline \end{NiceTabular} \end{minipage} & \begin{minipage}[m]{0.55\textwidth} \renewcommand\textminus{\mbox{-}}%<<<<<<<<<<< \begin{lstlisting}[numberstyle=\zebra{green!15}{yellow!15},numbers=left,basicstyle=\footnotesize] \documentclass{article} \usepackage[table]{xcolor} \usepackage{nicematrix} \NiceMatrixOptions{cell-space-top-limit=5pt,cell-space-bottom-limit=5pt}

\begin{document} \begin{table}[htbp] \centering \begin{NiceTabular}{|c|c|c|} \hline \cellcolor{red}1& \cellcolor{green}1 & \cellcolor{black!10}1 \ \hline \cellcolor{orange}1 & \cellcolor{red!35}1 & \cellcolor{brown!50}1 \ \hline \cellcolor{green!35}1 & \cellcolor{blue!45}1 & \cellcolor{yellow}1 \ \hline \end{NiceTabular} \end{table} \end{document} \end{lstlisting} \end{minipage} \end{tabular}

\end{document}

David Carlisle
  • 757,742