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

when code contains non english comments, \newtcbinputlisting fails to show the comments! #131

Closed
zqudm opened this issue Feb 7, 2021 · 4 comments

Comments

@zqudm
Copy link

zqudm commented Feb 7, 2021

First , the code to be highlighted is shown as follows:
import numpy as np
a = np.array([1,2,3]) #这里是中文注释
print (a)

the above code is saved in a file named 'list1.py'

the latex source code is shown as follows:

\documentclass{article}

\newcounter{commentCount}
\newcounter{filePrg}
\newcounter{inputPrg}

\usepackage{geometry}
\geometry{paper=letterpaper,margin=2cm}

\usepackage{ifthen}

\usepackage{fontawesome}

\usepackage[dvipsnames]{xcolor}

\usepackage{tabularx}
\newcolumntype{\CeX}{>{\centering\let\newline\\\arraybackslash}X}%
\newcommand{\TwoSymbolsAndText}[3]{%
	\begin{tabularx}{\textwidth}{c\CeX c}%
		#1 & #2 & #3
	\end{tabularx}%
}

\usepackage{minted}

\usepackage[many]{tcolorbox}
\tcbuselibrary{listings}
\tcbuselibrary{minted}



\newtcbinputlisting[use counter=filePrg, number within=section,number format=\arabic]{\codeFromFile}[4]{%
	listing engine=minted,
	minted language=#1,
	listing file={#2},
	minted options={autogobble,linenos,breaklines},
	listing only,
	size=title,
	arc=1.5mm,
	breakable,
	enhanced jigsaw,
	colframe=brown,
	coltitle=White,
	boxrule=0.5mm,
	colback=white,
	coltext=Black,
	title=\TwoSymbolsAndText{\faCode}{%
		\textbf{File program \thetcbcounter}\ifthenelse{\equal{#3}{}}{}{\textbf{:} \textit{#3}}%
	}{\faCode},
	label=filePrg:#4
}



\usepackage{cleveref}
\crefname{commentCount}{comment}{comments}
\crefname{filePrg}{file program}{file programs}
\crefname{inputPrg}{input program}{input programs}

\begin{document}

	
\codeFromFile{python}{list1.py}{Another welcome program.}{code01}
	

\end{document}

However, after compiling the latex code above to a pdf document, the comment in the source code does not exist. How to solve this issue? Thanks!

@muzimuzhi
Copy link
Contributor

muzimuzhi commented Feb 7, 2021

Please edit your issue to (always) mark the codes as fenced code blocks in GitHub Flavored Markdown. For example,

```tex
\documentclass{article}
<more lines>
```

This avoids wrongly creating issue references to #1, #2, ... .

@muzimuzhi
Copy link
Contributor

@zqudm You didn't specify the capable font used to typeset Chinese. You may find Missing Character ... errors in log file, for example after compiling with xelatex, the log will contain

Missing character: There is no 这 in font [lmmono10-italic]:!
Missing character: There is no 里 in font [lmmono10-italic]:!
Missing character: There is no 是 in font [lmmono10-italic]:!
Missing character: There is no 中 in font [lmmono10-italic]:!
Missing character: There is no 文 in font [lmmono10-italic]:!
Missing character: There is no 注 in font [lmmono10-italic]:!
Missing character: There is no 释 in font [lmmono10-italic]:!
Missing character: There is no 这 in font [lmmono10-italic]:!
Missing character: There is no 里 in font [lmmono10-italic]:!
Missing character: There is no 是 in font [lmmono10-italic]:!
Missing character: There is no 中 in font [lmmono10-italic]:!
Missing character: There is no 文 in font [lmmono10-italic]:!
Missing character: There is no 注 in font [lmmono10-italic]:!
Missing character: There is no 释 in font [lmmono10-italic]:!

This is reproducible in the following simpler example, hence has nothing to do with tcolorbox.

% compile with xelatex or lualatex
\documentclass{article}
\begin{document}
中文
\end{document}

Loading ctex package would be the quickest solution.

@zqudm
Copy link
Author

zqudm commented Feb 9, 2021

including ctex package indeed works! Additionally, i just wonder how to elegantly typeset the running results of program, i.e., output of the program?

@muzimuzhi
Copy link
Contributor

It depends, and is off-topic here. Try tex.stackexchange.com or https://github.com/CTeX-org/forum instead.

@T-F-S T-F-S closed this as completed Feb 16, 2021
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

3 participants