1

I've spent few days already trying to properly include a Java source file dynamically in a tex file. The text is included. However the lines don't wrap.

The following is the "srinked" project

\documentclass{article}  

\usepackage[left=2.54cm, right=2.54cm, top=2.54cm, bottom=2.54cm]{geometry}  

\usepackage{listings}  
\usepackage{adjustbox}  
\usepackage{wrapfig}  
%%\usepackage[none]{hyphenat}  

\usepackage[T1]{fontenc}  
\usepackage[cp1252]{inputenc}  
\usepackage{lmodern}  
\usepackage[english]{babel}  

\usepackage[usenames,dvipsnames]{xcolor}  

\usepackage{graphicx}  
\graphicspath{{images/}{../images/}}  



%% All duplicates have been commented out  

\usepackage[ampersand]{easylist}  
\usepackage{ulem}    
\usepackage{csquotes}    

\newcommand{\quotes}[1]{``#1''}  
\usepackage{textcomp}  

\usepackage{tikz}  
\usetikzlibrary{calc, shapes, backgrounds}  
\usepackage{amsmath, amssymb}  

\usepackage{verbatim}  
\usepackage{pdflscape}  
\usepackage{wallpaper}  

\usepackage{framed}  
\usepackage{float}  

\lstdefinestyle{MyJavaListStyle} {  
    numbers=left,  
    language=Java,  
    backgroundcolor={\color{yellow}},  
    breaklines=true  
    }  

\usepackage{filecontents}  

\begin{document}  

Begining of the document.  

\begin{filecontents*}{file.java}  
                                                }  

    static void testMe() {  
        String[][] arrTest = {  

                { "John ", "Doe", "24a", "121", "new McGill College",  
                        " a Suite 32", "2r223", "Montréal Name Of The Town1"  
                        "", "Québec", "K1A 2E3W3", "Canada" },  
                { "Zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzmabcdefghijklmnopqrstuvwxyzmabcdefghijklmnopqrs", "GivenNameZabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzmabcdefghijklmnopqrstuvwxyzmabcdefghij",  
                        "24arererere_rerere",  
                        "121ere",  
                        "new McGill College McGill College McGill College McGill Collegea",  
                        " a Suite 32", "2r223",  
                        "Montréal Long City Name On My So So It Is Split onto",  
                        "", "Québec", "K1A 2E3", "Canada" }, };  

                                    String cpfn = m_busCompCCP.getFieldValue("CIC EAI Person Family Name"); // **report**  
                                    String cpgn = m_busCompCCP.getFieldValue("CIC EAI Person Given Name") ; //**report**  
                                    String ctdob = m_busCompCCP.getFieldValue("CIC EAI Person Textual Birth Date"); // **report**  

                                    try {  
                                        oAR.sCICPrimaryGivenName = cpgn;  
                                        oAR.sCICTextualDOB = ctdob;  
                                        // we have the data, add-it to the  
                                        // result set  

                                                                            // addonlythearchived ones; redundant check, should have been  
                                                                                                           // filtered already at the search spec BC                                        
                                        //if (status.equals(archivedENU) || status.equals(archivedFRA))  
                                            listArchiveLabel.add(oAR);   

                                    } catch (Exception exa) {  
                                        System.out  
                                                .println("Error adding a row from the result set:"  
                                                        + exa.toString());  
                                    }  
                                    bFound6 = m_busCompCCP.nextRecord();  
                                }  
                                bFound5 = m_busCompCACO.nextRecord();  
                            }  
                            bFound4 = m_busCompCPOC.nextRecord() ;  
                        }  
                        bFound3 = m_busCompCAMC.nextRecord();  
                    }  
                    bFound2= m_busCompAMAR.nextRecord();  


\end{filecontents*}  

\begin{landscape}

$$Retrieve\ methods$$  
\begin{framed} 
     \lstinputlisting[style=MyJavaListStyle,  
       linerange={1-549},  
       firstnumber=1,  
       caption=file.java,  
       ]{file.java}  
\end{framed}  

\end{landscape}

Continuation of the document.

\end{document}  

Images: first wrap

another wrap

  • 4
    It is much easier to help if you make your example a complete document that people can run locally and test answers. – David Carlisle Feb 12 '15 at 19:37
  • related: http://tex.stackexchange.com/questions/175719/what-in-the-custom-class-i-use-prevents-line-breaking-in-listings/176167#176167 – jub0bs Feb 13 '15 at 08:29
  • 2
    Thank you for posting a working example! At the same time, much of your code does not seem to be relevant to the question you're asking here. Please limit the example to only the code required for your issue to appear. You can have a look at this guide for how to prune your code for this purpose. – Martin Schröder Feb 16 '15 at 22:00
  • 1
    After some testing it may look like the hyphenat package is somehow the culprit, but you should investigate this yourself, and it would be nice if you reduced your example as Martin mentions above. – Torbjørn T. Feb 18 '15 at 12:21
  • Hi Torbj\orn. Taking out the hypenat package works nearly perfect. The exceptions are when a line have too many spaces before wrapping. I'm adding a screen shot. – Iosif Tanasescu Feb 18 '15 at 16:58
  • I don't really understand what you mean, and sorry, but I won't try to modify your code to reproduce that behaviour. Please reduce your code to the absolute minimum showing the problem. Use \begin{lstlisting}<code>\end{lstlisting} instead of \lstinputlisting{filename}, drop the subfiles stuff, remove all figures, all text, all packages that doesn't affect this etc. We should be able to copy-paste the code into an empty file and compile it without modifications, and the PDF should show the problem. – Torbjørn T. Feb 18 '15 at 18:42
  • As requested, I've changed the code with a chopped one. Please see the output of lines 9, 26, and 27. As for the real code, I did reformat the code, dropping leading tabs/spaces and now is showing nearly all correctly, except some cases as above. – Iosif Tanasescu Feb 19 '15 at 15:20
  • There is simply too many space/indentation. And how the hell is listings suppossed to know, where to break a string of letters? – Johannes_B Feb 22 '15 at 13:59
  • Just added two samples of wrapping of a line of 288 characters in Notepad++ editor (any text editor) – Iosif Tanasescu Feb 23 '15 at 19:46
  • Noticed this question again, and while you've probably stopped looking for a solution: Listings package does not break solves line 9. For line 27, do you really want 107 spaces at the start of the line? Reducing it to 40 makes more sense with the try/catch, and makes the listing look better. – Torbjørn T. Sep 06 '15 at 10:49

0 Answers0