lstinputlisting adds cryptic line - latex

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}

Related

Package listings error: numbers true unknown

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:

Why is hyperref package causing an issue with \footnotemark?

I had recently posted a question seeking help for linking a glossary in a specific way and it was resolved, thanks to #samcarter_is_at_topanswers.xyz for helping me out. url to the post
Now, going ahead with the suggestions, I make use of \hyperref package in my project and that is causing an issue with the use of \footnotemark[]. I have attached the screenshots below along with a MWE.
Screenshots :
With the hyperref package I get the error :
Without the hyperref package I get the output with no errors :
MWE :
\documentclass{article}
\usepackage[utf8]{inputenc} % Input encoding (this file): 8 bit unicode. Default by most text editors
\usepackage[T1]{fontenc} % Output encoding (pdf file)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages used in the example
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx} % Included graphics and some resizable boxes
\usepackage{url} % nice urls with line breaks
\usepackage{lipsum} % nonsense text blocks
\usepackage{float}
\usepackage{subcaption}
\usepackage{multicol}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{biblatex}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage[nonumberlist,acronym,
entrycounter=true
]{glossaries}
\makeglossaries
\newglossaryentry{vp}
{
name= Verification Plan,
description={A verification plan is a list of the procedures and methods to be used for verification}
}
\newacronym{ml}{ML}{Machine Learning}
%%UNCOMMENT THIS AND THERE IS AN ERROR WITH GLOSSARY
%\usepackage{hyperref}
%\hypersetup{
% citecolor=black,
% colorlinks=false, %set true if you want colored links
% linktoc=all, %set to all if you want both sections and subsections linked
% linkcolor=black, %choose some color if you want links to stand out
%}
\begin{document}
%\glsaddall
\setglossarystyle{altlist}
\printglossary
\printglossary[type=\acronymtype]
------
\textbf{Develop}: The develop phase includes \gls{vp}\footnotemark[\glsrefentry{vp}], creating verification environment, testbench and test case development. \acrfull{ml}
\end{document}
So in short, I want to have my glossary hyperlinked along with referencing it by using \footnotemark[\glsrefentry....].
Any solution/advice would be greatly appreciated! Thanks in advance!
With hyperref, the \glsrefentry{...} macro is a link to your list of acronyms, which conflicts with using it as a footnotemark. You can use e.g. \textsuperscript{...} as a workaround:
\documentclass{article}
\usepackage[utf8]{inputenc} % Input encoding (this file): 8 bit unicode. Default by most text editors
\usepackage[T1]{fontenc} % Output encoding (pdf file)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Packages used in the example
\usepackage[dvipsnames]{xcolor}
\usepackage{graphicx} % Included graphics and some resizable boxes
\usepackage{url} % nice urls with line breaks
\usepackage{lipsum} % nonsense text blocks
\usepackage{float}
\usepackage{subcaption}
\usepackage{multicol}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{biblatex}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage[nonumberlist,acronym,
entrycounter=true
]{glossaries}
\makeglossaries
\newglossaryentry{vp}
{
name= Verification Plan,
description={A verification plan is a list of the procedures and methods to be used for verification}
}
\newacronym{ml}{ML}{Machine Learning}
%UNCOMMENT THIS AND THERE IS AN ERROR WITH GLOSSARY
\usepackage{hyperref}
\hypersetup{
citecolor=black,
colorlinks=false, %set true if you want colored links
linktoc=all, %set to all if you want both sections and subsections linked
linkcolor=black, %choose some color if you want links to stand out
}
\begin{document}
\glsaddall
\setglossarystyle{altlist}
\printglossary
\printglossary[type=\acronymtype]
------
\textbf{Develop}: The develop phase includes \gls{vp}\textsuperscript{\glsrefentry{vp}}, creating verification environment, testbench and test case development. \acrfull{ml}
\end{document}

Add line numbers to Rmarkdown text and have it restart on each page

I am knitting my markdown file and I have included the following in my header, which produces line numbers in my text. How can I make the numbering reset at the beginning of each new page?
header-includes:
\usepackage{lineno}
\linenumbers
The lineno package has an option to restart the line number automatically for each page:
\usepackage[pagewise]{lineno}
Minimal working example:
\documentclass{article}
\usepackage[pagewise]{lineno}
\linenumbers
\usepackage{lipsum}
\begin{document}
\lipsum
\end{document}

Changing the header of the exported latex

The standard header of the latex file exported from org is:
\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fixltx2e}
etc.
My .org file contains text in Hebrew. To make that work with latex, I need to modify the header as follows:
\documentclass[11pt]{article}
% BEGIN for Hebrew support
\makeatletter
\let\l#hebrew\l#nohyphenation
\makeatother
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[english, hebrew]{babel}
% END for Hebrew support
% DISABLED \usepackage[utf8]{inputenc}
% DISABLED \usepackage[T1]{fontenc}
\usepackage{fixltx2e}
etc.
I tried beginning my org file like this:
#+LATEX_HEADER: \makeatletter
#+LATEX_HEADER: \let\l#hebrew\l#nohyphenation
#+LATEX_HEADER: \makeatother
#+LATEX_HEADER: \usepackage{ucs}
#+LATEX_HEADER: \usepackage[utf8x]{inputenc}
#+LATEX_HEADER: \usepackage[english,hebrew]{babel}
However, this inserts the lines much later in the header than needed. Also, it does not take care of removing the lines that need to be removed to avoid conflicts.
Is it possible to do what I need?

How can I get page numbers to link to the table of contents in latex?

I've seen a pdf LaTeX document where the page numbers at the bottom of the page are hyperref links, and clicking them causes you to jump to the contents table. I don't have the tex file and couldn't work out how it's done from the hyperref package. Can anyone help?
You could set an anchor at the toc and redefine \thepage to link to it. Here's an example:
\documentclass{report}
\usepackage[colorlinks]{hyperref}
\renewcommand*{\contentsname}{\hyperlink{contents}{Contents}}
\renewcommand*{\thepage}{\hyperref[contents]{\arabic{page}}}
\begin{document}
\tableofcontents
\chapter{One}
Text
\end{document}
If you use babel and wish to redefine \contentsname, use the \addto command of babel or redefine \contentsname after \begin{document}.
Have you tried defining the page numbering using this?
\pagestyle{myheadings}
\markright{ ... }
where \markright specifies the page number with a link to the content page.
Here is how I did it
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = xelatex
\documentclass[UTF8, english]{article}
\usepackage{lipsum} %% produce dummy texts
\usepackage{hyperref}
\usepackage[pagestyles]{titlesec}
\newpagestyle{article}{
\setfoot
%% even pages
[]
[\footnotesize \hyperlink{toc}{\thepage}]
[]
%% odd pages
{}
{\footnotesize \hyperlink{toc}{\thepage}}
{}
}
\begin{document}
\title{example}
\date{}
\author{author}
\maketitle
\pagenumbering{roman}
\setcounter{tocdepth}{2}
\addtocontents{toc}{\protect\hypertarget{toc}{}}
\tableofcontents
\newpage
\pagenumbering{arabic}
\pagestyle{article}
\section{A}
\lipsum[1]
\subsection{a}
\lipsum[2]
\subsection{b}
\lipsum[3]
\subsection{c}
\lipsum[4]
\section{B}
\lipsum[5]
\subsection{d}
\lipsum[6]
\subsection{e}
\lipsum[7]
\section{C}
\lipsum[8]
\subsection{f}
\lipsum[9]
\subsection{g}
\lipsum[10]
\subsection{h}
\lipsum[11]
\end{document}
you can of course customize the link text back to table of contents however you like in the preamble, please read documentation of titlesec for more details.

Resources