0

I am using dissertation template. Following is the link:

https://www.overleaf.com/read/yyjwyqtvzfwt#ef4aff

Can anybody get access to all my documents using the above link?

I am trying to represent the Solidity code listing as figures. I have written the following code listing for representing as a figure as shown below:

\begin{figure}
  \caption{Example of Information Flow Rules}
\begin{lstlisting}
[language=Solidity, label={lst:Etahinter1}]
contract IFR{
function initOwner(address _owner) public { owner = _owner;}
function EasyTokill() public {
   if (msg.sender == owner)
   { /* sensitive code like selfdestruct or Ether transfer statement */ ... }}
}
\end{lstlisting}
\end{figure}

The resultant latex listing shows the following unwanted line at the top sometimes and sometimes not:

[language=Solidity, label={lst:Etahinter1}]

Please guide me how to get rid of the above line. Zulfi.

2
  • you could more helpfully supply a test document, it does not have to have any words from your real document but should be a complete small document that people can test. It is safest to put the optional argument immediately after \begin{lstlisting} Commented Dec 9, 2023 at 23:49
  • Please post a minimal example here. Posts should not rely on external links.
    – cfr
    Commented Dec 10, 2023 at 2:45

1 Answer 1

0

The optional argument needs to be straight after \begin{listing} otherwise it is read verbatim as part of the listing.

This is shown in the second block below, but I get

! Package Listings Error: Couldn't load requested language.

See the Listings package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.20 ...language=Solidity, label={lst:Etahinter2}]
                                                  
? 

! Package Listings Error: language solidity undefined.

See the Listings package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.20 ...language=Solidity, label={lst:Etahinter2}]
                                                  
? 

But perhaps you have a local extension that defines this listings configuration.

enter image description here

\documentclass{article}

\usepackage{listings}

\begin{document}
\begin{figure}
  \caption{Example of Information Flow Rules}
\begin{lstlisting}
[language=Solidity, label={lst:Etahinter1}]
contract IFR{
function initOwner(address _owner) public { owner = _owner;}
function EasyTokill() public {
   if (msg.sender == owner)
   { /* sensitive code like selfdestruct or Ether transfer statement */ ... }}
}
\end{lstlisting}

\bigskip \hrule \bigskip

\begin{lstlisting}[language=Solidity, label={lst:Etahinter2}]
contract IFR{
function initOwner(address _owner) public { owner = _owner;}
function EasyTokill() public {
   if (msg.sender == owner)
   { /* sensitive code like selfdestruct or Ether transfer statement */ ... }}
}
\end{lstlisting}
\end{figure}
\end{document}
4
  • Based on your comments, I have developed Figure 4.2. It does not have unwanted listing control, but it has a huge horizontal line above the figure, and there is a huge space. Please guide me how to get rid of the huge horizontal line and huge space . overleaf.com/project/6531bd5d181592ed690d9384 Zulfi. Commented Dec 10, 2023 at 0:57
  • 1
    the \bigskip \hrule \bigskip is just for this example to separate the two listings, not for you to copy @user2994783 Commented Dec 10, 2023 at 2:45
  • Actually the problem was in the line: \begin{lstlisting}[language=Solidity, label={lst:Etahinter2}]. Previously I was inserting a carriage return after: \begin{lstlisting}. Actually I was writing: "\begin{lstlisting}" and in the next line I was writing:"[language=Solidity, label={lst:Etahinter2}]". Thanks a lot. God blesses you. Commented Dec 10, 2023 at 15:23
  • @user2994783 yes that's what I show here "The optional argument needs to be straight after \begin{listing}" Commented Dec 10, 2023 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .