Package listings error: numbers true unknown - latex

Im getting a warning, as in tittle. Because of that (I think so) I cant see specified bacground colors and so on. Below I paste the source code.
The error tells that it do not recognize the "true - how can I fix that?
\documentclass[final,3p,times]{elsarticle}
\pgfplotsset{compat=1.18}
\begin{document}
\textbf{Appendix: moving mesh}
\lstinputlisting[language=python, captionpos=t, label={ListingRecHEL1}]{data/code.py}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.6,0.9,0.1}
\renewcommand{\lstlistingname}{Kod}% Listing -> Algorithm
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{orange},
basicstyle=\ttfamily\tiny,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2
name = "Kod"
}
\lstset{style=mystyle}
\clearpage
\end{document}

I have no clue what this documentclass is, so I used a KOMA class. Should have no effect on lstlisting.
And mentioned in the comments, your example is not a working MWE, it is messed up with code that is not helpful to solve your issue.
The trick is simple: Just read the compilers messages. When it tells you, that there is an unknown option, you should try to remove it and compile again. numbers=true is not valid and not needed.
Doc of listings
A working example that may come close to yours:
\documentclass[]{scrartcl}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{hyperref}
\begin{document}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.6,0.9,0.1}
\renewcommand{\lstlistingname}{Kod}% Listing -> Algorithm
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{orange},
basicstyle=\ttfamily\tiny,
breakatwhitespace=false
commentstyle=\color{codegreen},
keywordstyle=\color{codepurple},
numberstyle=\tiny\color{codegray},
stringstyle=\color{orange},
basicstyle=\ttfamily\tiny,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
%numbers=true % <-----your tex compiler tells you that it is unknown
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
name = "Kod"
}
\lstinputlisting[
language=python,
style=mystyle,
captionpos=t,
caption={My Python program},
label={lst:promise}
]{code.py}
In \autoref{lst:promise} I did my very best.
\end{document}
The code.py:
def main():
"""This is a function"""
return 'I will provide MWE when asking LaTeX related questions.'
# and this a line comment
if __name__=='__main__':
print(main())
The result:

Related

using initial line numbering with listings package in latex

Is there the posibility to use the initial line numbering from the code I want to list in my latex file? So the code should be numbered like in the picture:
But using the following code, the numbering starts from 1
\lstinputlisting[language=C,
numbers=left,
numberfirstline=false,
keywordstyle=\color{blue},
commentstyle=\color{green},
stringstyle=\color{red},
firstline=222, lastline=228]{Test_Fehlerbehebung_LIN.can}
And why is the first number (1) obove the first row? Shouldn't numberfirstline=false fix this problem?
This ist the minimal example:
\documentclass[]{scrreprt}
\usepackage{colortbl}
\usepackage{listings}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
%backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{black},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
firstnumber=auto
}
\begin{document}
\lstset{basicstyle=\footnotesize, style=mystyle}
\lstinputlisting[language=C]{Code/Test_Fehlerbehebung_LIN.c}
\end{document}
You can use the same fix as in https://tex.stackexchange.com/a/27240/36296
\documentclass[]{scrreprt}
\usepackage{colortbl}
\usepackage{listings}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
numbers=left,
}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\lst#GLI#}% <command>
{\def\lst#firstline{#1\relax}}% <search>
{\def\lst#firstline{#1\relax}\def\lst#firstnumber{#1\relax}}% <replace>
{\typeout{listings firstnumber=firstline}}% <success>
{\typeout{listings firstnumber not set}}% <failure>
\makeatother
\begin{document}
\lstset{basicstyle=\footnotesize, style=mystyle}
\lstinputlisting[language=C,firstline=10, lastline=20,firstnumber=firstline]{document.tex}
\end{document}

Why am I getting "Argument of "?" has an extra } \end{titlepage}" when downloading overleaf project which compiles fine there [duplicate]

I got a new PC with Windows 10 Pro operating system several days ago and decided to install TeXstudio + MiKTeX.
And I faced a problem compiling LaTeX file. The problem is when I try to add \usepackage{hyperref} or code stuff similar to this line (more detailed in the code with the comment line % problem is here if I add this line) I get an error which says: Argument of � has an extra }. \end{document}.
My code:
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
\usepackage{ucs}
\usepackage[pdftex]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{color}
\definecolor{Black}{rgb}{0,0,0}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\usepackage{xcolor}
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
\begin{document}
Random text
${\mathcal {E}}=-{{d\Phi_{B}} \over dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}
Error I get:
Error
When I try this code in OverLeaf or on my notebook or without hyperref packages - everything's fine. But I need this package if, for example, I'll have to add references...
Did someone face similar problem? Maybe I need to install some other packages?
A quote from the hyperref maintainer:
But I would recommend to drop utf8x/ucs. Most improvements in the handling of utf8 which e.g. allow you to use them in \labels and filenames are undone by utf8x/ucs.
If the ucs package and utf8x inputenc option is removed, your code compiles.
Furthermore you should remove the pdftex from graphicx. It will automatically choose the best suited option to match your compilation chain.
You should also not load the same package multiple times, in particular not with different options
And load hyperref after the other packages (there are only very view exceptions)
No need to load color if you also load xcolor
\documentclass[10pt,a4paper]{report}
\usepackage{cmap}
\usepackage{setspace}
\onehalfspacing
\usepackage{multicol}
\usepackage{textcomp}
\usepackage{verbatim}
\usepackage{floatrow,calc}
\DeclareFloatSeparators{mysep}{\hspace{3cm}}
\thisfloatsetup{floatrowsep=mysep}
%\usepackage{ucs}
\usepackage[
%pdftex
]{graphicx}
\usepackage{epstopdf}
\usepackage{amssymb,amsmath}
\DeclareGraphicsExtensions{.pdf, .png, .jpg}
\usepackage[labelsep=period]{caption}
%\usepackage[utf8x]{inputenc}
\usepackage[T2A]{fontenc}
\usepackage[russian, english]{babel}
\usepackage[left=3cm, right=1.5cm, top=1.5cm, bottom=2cm]{geometry}
\usepackage{indentfirst}
\usepackage{xcolor}
\definecolor{Black}{rgb}{0,0,0}
\fontfamily{ptm}
\parindent=1cm
\sloppy
\bibliographystyle{unsrt}
%\usepackage{hyperref} % problem is here if I add this line
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\lhead{\leftmark}
\cfoot{\thepage}
\renewcommand{\headrulewidth}{1pt}
\usepackage{subfig}
\usepackage{epigraph} %%% to make inspirational quotes.
\usepackage{amsfonts}
%\usepackage{xcolor}
\usepackage[unicode, colorlinks, linkcolor=Black]{hyperref} % problem is here if I add this line
\definecolor{linkcolor}{HTML}{000000}
\definecolor{urlcolor}{HTML}{000000}
\hypersetup{pdfstartview=FitH, linkcolor=linkcolor, urlcolor=urlcolor, colorlinks=True} % problem is here if I add this line
\begin{document}
Random text
${\mathcal {E}}=-\frac{{d\Phi_{B}} }{ dt},$ where
${\mathcal {E}}$ — random letter.
\end{document}

Overleaf/Latex. How do I add APA 6th edition citation style?

[EDIT]
I am having issues changing the citation style to my document. I am currently working with this preamble. There are a lot of packages, but I need them to organise the entire file. The current code works ok, but the citation style is not correct. I need to change it to apa 6th edition.
Preamble:
\documentclass[11pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{helvet}
\usepackage{xspace}
\usepackage{subcaption}
\usepackage{placeins}
\usepackage{wrapfig}
\usepackage{multirow}
\usepackage[table,xcdraw]{xcolor}
\usepackage{adjustbox}
\usepackage{booktabs,caption}
\usepackage[flushleft]{threeparttable}
\usepackage{ragged2e}
\usepackage{floatrow}
\usepackage{graphicx,wrapfig,lipsum}
\graphicspath{{../figs/}}
\usepackage{pdfcomment}
\usepackage{geometry}
\newgeometry{left=2.5cm,right=2.5cm,bottom=2.5cm}
\usepackage[english]{babel}
\usepackage{CJKutf8}
\pagestyle{headings}
\usepackage{blindtext}
\usepackage{csquotes}
\setcounter{secnumdepth}{4}
\usepackage{titlesec}
\usepackage[T1]{fontenc}
\usepackage{imakeidx}
\makeindex[columns=3, title=Alphabetical Index]
\usepackage{array}
\usepackage{tikzpagenodes}
\usepackage[format=plain, labelfont={bf,it}, textfont=it]{caption}
\usepackage{fancyhdr}
\usepackage[toc,nopostdot, nonumberlist,style=long,automake,acronym]{glossaries}
\usepackage{subfiles}
\usepackage{nicematrix}
\usepackage{amsmath,mathabx}
\usepackage{hyperref}
\usepackage{lscape}
\newcommand{\sectionbreak}{\phantomsection}
\hypersetup{
colorlinks=true,
linkcolor=black,
filecolor=black,
urlcolor=black,
citecolor=olive,
pdftitle={PhD Dissertation},
pdfpagemode=FullScreen,
}
\urlstyle{same}
%\bibliographystyle{abbrvnat}
%\usepackage[authoryear]{natbib}%/bibliography apa
%\setcitestyle{authoryear,open={(},close={)}} %Citation-related commands
The bibliography file called bib.bib
Example:
#article{henriquez_alternative_2017,
title = {An alternative objective microscopic method for the identification of linear enamel hypoplasia ({LEH}) in the absence of visible perikymata},
volume = {14},
doi = {10.1016/j.jasrep.2017.05.040},
journal = {Journal of Archaeological Science: Reports},
author = {Henriquez, Alejandra Cares and Oxenham, Marc F.},
year = {2017},
pages = {76--84},
file = {Full Text:C\:\\Users\\xello\\Zotero\\storage\\MV7QMSWQ\\Henriquez and Oxenham - 2017 - An alternative objective microscopic method for th.pdf:application/pdf},
}
Example of text citing something
\begin{document}
\begin{CJK*}{UTF8}{min}
\citep{henriquez_alternative_2017}, \citet{henriquez_alternative_2017}.
\end{CJK*}
\end{document}
I need to change the citation style to apa6: https://www.ctan.org/pkg/apa6. When Io tried to add this package. It entered into conflict with other packages like titlesec and amsmath, mathabx.
I get errors like
...ex/titlesec/titlesec.sty, 1642. Argument of \subparagraph has an
extra }. or Runaway argument?
or
eric/mathabx/mathabx.sty, 67. Latex Error: Too many symbol fonts
declared.
respectively.
I am not sure how to add this citation style to my current project. Maybe there is an alternative way? I need the packages I am using (like titlesec) to order my document.
Any help will be welcomed.
Thank you,
[EDIT] Solved it. I used Biblatex (https://ctan.org/pkg/biblatex-apa6?lang=en) which also has an apa6 option. Solved additional errors. Works well.

lstinputlisting adds cryptic line

i am using lstinputlisting in a latex document to include some source code. When I am giving a specific line range or firstline to start with there is a cryptic line added directly before my code looking like that:
code line added by latex
My latex code:
\lstset{ % Konfiguration
xleftmargin=0.5cm,
language=C++, % C++ als Sprache vordefinieren. Optional überschreiben
basicstyle=\small,
backgroundcolor=\color{lgray},
keywordstyle=\color{black}\bfseries,
commentstyle=\color{black}\small,
showstringspaces=false,
numbers=left,
numberstyle=\tiny,
numbersep=5pt,
breaklines=true,
tabsize=4,
showtabs=false,
}
\lstinputlisting[linerange=739-745]{Marlin/Configuration.h}
Does someone know where this line comes from and how to fix it?
Minimal example:
\documentclass[12pt, ngerman]{scrreprt}
\usepackage{listings}
\begin{document}
\lstinputlisting[linerange={740-745}]{example.h}
\end{document}

How to supress any title or caption for \lstinputlisting?

I am using
\lstinputlisting[]{javacode/DatabaseManager-getUser}
to show some java code. However the following caption appears underneath the listing (see picture marked with red arrow):
In my preamble I have used \lstset to set title={}, however I don't want anything there, no title or caption. Is this possible? And if so how would I go about doing it?
See MattAllegros comment in OP. It made me find the issue. In my preamble I had the following setup:
\usepackage{listings}
\lstset{ %
backgroundcolor=\color{grayC},
basicstyle=\ttfamily\small,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
commentstyle=\color{greencomments},
deletekeywords={...},
escapeinside={(*#}{#*)},
extendedchars=true,
frame=single,
keepspaces=true,
keywordstyle=\color{bluekeywords},
language=Java,
morekeywords={partial, var, value, get, set},
numbers=left,
numbersep=5pt,
numberstyle=\tiny\color{black},
rulecolor=\color{Dgray},
showspaces=false,
showstringspaces=false,
showtabs=false,
stepnumber=1,
stringstyle=\color{redstrings},
tabsize=2,
morekeywords= {new, std::*,},
title={}
}
I commented out captionpos=b and title={}, and now I get nothing underneath the listing as was what I wanted in OP. for output comparrison see:

Resources