Embark on a journey of knowledge! Take the quiz and earn valuable credits.
Take A QuizChallenge yourself and boost your learning! Start the quiz now to earn credits.
Take A QuizUnlock your potential! Begin the quiz, answer questions, and accumulate credits along the way.
Take A QuizGeneral Tech Bugs & Fixes 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
As described in the documentation of the listings package, you have to define the caption and label in the options of the lstlisting environment. This is required because any text within lstlisting is typeset, so your code prints \label{phpheg} in the PDF, instead of calling that as a LaTeX command.
\documentclass{article}
\usepackage{listings}
\begin{document}
See Listing~\ref{phpheg} for details.
\begin{lstlisting}[caption={PHP Code},label=phpheg]
$id = addslashes($_GET['id']);
\end{lstlisting}
More text.
\end{document}
Note: as Werner says in his comment, as everything between \begin{lstlisting} and \end{lstlisting} is printed, thus indented code is also typeset indented. As a work-around, you can (and should) write the listing without any indention (as above).
As proposed by MaxNoe, you can use the lstautogobble package as a workaround: simply add \usepackage{autogobble} and set autogobble=true in the settings of lstlistings.
No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.
Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 years ago
Hello can somebody please show the correct way to display my source code in Latex
The following
codeI want to display asphp codeHow can I display the above
codeinLatexassource code? In My document .I tried the below but get an error about a label not yet been referenced