1

This question already has an answer here:

i am having troubles inserting XML code in Latex because the code lines appear out of the margins.

First at all, i have defined the style, by the following way:

\documentclass[a4paper,11pt]{book}
\usepackage{listings, color}
\usepackage[utf8]{inputenc}
\usepackage[spanish, es-tabla]{babel}
\usepackage{booktabs}

\decimalpoint
\usepackage{dcolumn}
\newcolumntype{.}{D{.}{\esperiod}{-1}}
\makeatletter
\addto\shorthandsspanish{\let\esperiod\es@period@code}
\makeatother

\RequirePackage{verbatim}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{afterpage}

\usepackage{lscape}

\usepackage[pdfborder={000}]{hyperref} %referencia

\usepackage[T1]{fontenc}
\usepackage{lmodern} % use a font family that supports accented characters natively
\usepackage{array,longtable,ragged2e,booktabs}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}

\usepackage[textwidth=13cm]{geometry} % choose text width here

\usepackage{url}
\usepackage{colortbl,longtable}
\usepackage[stable]{footmisc}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LO]{\leftmark}
\fancyhead[RE]{\rightmark}
\fancyhead[RO,LE]{\textbf{\thepage}}
\renewcommand{\chaptermark}[1]{\markboth{\textbf{#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\textbf{\thesection. #1}}}

\setlength{\headheight}{1.5\headheight}

\newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

\lstset{ frame=Ltb,
     framerule=0.5pt,
     aboveskip=0.5cm,
     framextopmargin=3pt,
     framexbottommargin=3pt,
     framexleftmargin=0.1cm,
     framesep=0pt,
     rulesep=.4pt,
     backgroundcolor=\color{gray97},
     rulesepcolor=\color{black},
     %
     stringstyle=\ttfamily,
     showstringspaces = false,
     basicstyle=\scriptsize\ttfamily,
     commentstyle=\color{gray45},
     keywordstyle=\bfseries,
     %
     numbers=left,
     numbersep=6pt,
     numberstyle=\tiny,
     numberfirstline = false,
     breaklines=true,
   }


% minimizar fragmentado de listados
\lstnewenvironment{listing}[1][]
   {\lstset{#1}\pagebreak[0]}{\pagebreak[0]}

\usepackage{pdfpages}


% HERE START THE LIST DEFINITION PROBLEM!!!
\definecolor{forestgreen}{RGB}{34,139,34}
\definecolor{orangered}{RGB}{239,134,64}
\definecolor{darkblue}{rgb}{0.0,0.0,0.6}
\definecolor{gray}{rgb}{0.4,0.4,0.4}

\lstdefinestyle{XML} {
    language=XML,
    extendedchars=true, 
    breaklines=true,
    breakatwhitespace=true,
    emph={},
    emphstyle=\color{red},
    basicstyle=\ttfamily,
    columns=fullflexible,
    commentstyle=\color{gray}\upshape,
    morestring=[b]",
    morecomment=[s]{<?}{?>},
    morecomment=[s][\color{forestgreen}]{<!--}{-->},
    keywordstyle=\color{orangered},
    stringstyle=\ttfamily\color{black}\normalfont,
    tagstyle=\color{darkblue}\bf,
    morekeywords={attribute,xmlns,version,type,release},
    otherkeywords={attribute=, xmlns=},
}

Later i have used lstlisting and added the XML content:

\begin{lstlisting}[style=XML,fontadjust,columns=fullflexible]
<?xml version="1.0"?>
<dds version="5.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://community.rti.com/schema/5.1.0/rti_routing_service.xsd">

<!-- POR SI DEFINIMOS EL TIPO DE DATOS MEDIANTE UN ARCHIVO IDL 
        <types> 
                <include file="../../idl/SimpleAPDU.xml"/> 
        </types> 
-->


<!-- Se definen los puntos de entrada al adapter -->
<adapter_library name="adapters">
    <adapter_plugin name="mqtt">
        <!-- Replace with your location of the shared library -->
        <dll>mqttadapter</dll>
        <create_function>RoutingServiceMQTTAdapterPlugin_create</create_function>
    </adapter_plugin>
</adapter_library>


<!-- Se define la configuracion para la entidad Routing Service `rs0'-->
<routing_service name="rs1">
    <annotation>
        <documentation>MQTT-DDS bidirectional bridge</documentation>
    </annotation>


    <!-- Domain Route para traducir las ShapeType DDS Samples en ShapeType MQTT Messages
        -->
    <domain_route name="dds_to_mqtt">
        <!-- Participant 1: DDS Samples en Domain 0 -->
        <participant_1>
            <domain_id>0</domain_id>
            <!-- 
                    <registered_type name="APDU" type_name="com::rti::mqtt::SimpleAPDU" />      
            -->
        </participant_1>

\end{lstlisting}

Finally..the output is shown in this picture:

enter image description here

Can someone help me with this issue? I'd like to expand the margins and not to making the font-style size very smaller. Thanks in advance!!!

EDITED: I have added all the \usepackage, \documentclass and extras in my document to make it easier to compile.

marked as duplicate by jub0bs, Svend Tveskæg, user13907, Community Sep 7 '15 at 20:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Thank you Heiko Oberdiek! I hope my stay here will serve to increase my knowledge in LaTeX! – Lewis Sep 7 '15 at 14:26
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – jub0bs Sep 7 '15 at 15:21
  • Thank you for your note Jubobs! I have added the required tags and packages to my question. – Lewis Sep 7 '15 at 17:06
  • @Lewis Your code is far from minimal and doesn't compile. In the future, instead of having multiple snippets of code in your question, please add a minimal working example (MWE). Anyway, the problem stems from breakatwhitespace=true. You need to set breakatwhitespace to false. – jub0bs Sep 7 '15 at 18:40
  • Right Jubobs, i'll do it next time that way and thank you for your solution! It solved my problem!! – Lewis Sep 7 '15 at 20:12

Browse other questions tagged or ask your own question.