Hot answers tagged

55

You can define your own language. The best I could get so far: \usepackage{listings} \usepackage{color} \definecolor{gray}{rgb}{0.4,0.4,0.4} \definecolor{darkblue}{rgb}{0.0,0.0,0.6} \definecolor{cyan}{rgb}{0.0,0.6,0.6} \lstset{ basicstyle=\ttfamily, columns=fullflexible, showstringspaces=false, commentstyle=\color{gray}\upshape } \...


20

XML language has very limited support for keywords. You can define more keywords yourself: \lstset{ language=XML, morekeywords={encoding, xs:schema,xs:element,xs:complexType,xs:sequence,xs:attribute} }


19

DocBook is certainly the standard for XML documentation writing. I've heard of DITA, but couldn't tell you much about it. You can use ConTeXt to process XML. It works by defining a mapping between the XML tags and TeX markup instructions. This should give you the benefits of DocBook (universal, XML-based) and many of the benefits of ConTeXt in the document ...


18

I would consider (La)TeX to be ideally suited for exactly the purpose you mention. It is definitely flexible in the sense that you can follow a very basic approach of typesetting simple elements (you mention paragraphs and figures), and tweaking the layout at a later stage (table of contents, margins, stock-size). The latter is typically obtained via the ...


15

Here's another style which is rather hacky and stingy about additional whitespace because of the attribute delimiter that starts with a space: \definecolor{maroon}{rgb}{0.5,0,0} \definecolor{darkgreen}{rgb}{0,0.5,0} \lstdefinelanguage{XML} { basicstyle=\ttfamily, morestring=[s]{"}{"}, morecomment=[s]{?}{?}, morecomment=[s]{!--}{--}, commentstyle=\...


14

A synthesis of the previous answers that works best for me, especially w.r.t. highlighting the angle brackets. Using SVG Color names (svgnames): \lstdefinelanguage{XML} { basicstyle=\ttfamily\footnotesize, morestring=[b]", moredelim=[s][\bfseries\color{Maroon}]{<}{\ }, moredelim=[s][\bfseries\color{Maroon}]{</}{>}, moredelim=[l][\bfseries\...


14

XML is a file format not a language of any sort so asking for a general XML to latex is like asking for ASCII to latex. In general it depends what is in the XML file, one would not expect the same latex formatting for an XSLT program as a XHTML document, just because they both happened to use an XML syntax. In general you need to specify the styling you ...


14

The problem is that the following two lines in your \lstdefinelanguage{XML} are in conflict: morestring=[s]{>}{<}, morecomment=[s][\color{orange}]{<!--}{-->}, In addition, doesn't \lstdefinelanguage{XML} redefine the XML language settings, thereby losing a lot of configs? One of the most noticeable drawbacks is that you can no longer access ...


13

How does this XML system integrate with the rest of ConTeXt? It integrates extremely well through special xmlsetups. These setups let you define the behaviour for every element of the input tree. For more info consult the Context XML documentation or ask on the list. Why would anyone use such a system? Because you can rarely demand that the input be ...


12

There's every reason to expect that you'll succeed brilliantly with LaTeX in your endeavor to get your planned book published. Focusing on the content is certainly always an excellent strategy. As you write various chapters, try to separate decisions over content from decisions about how the content may/should be formatted. That said, I wonder if you wouldn'...


11

minted can’t do that and since I have no idea how this line-breaking feature is implemented in listings there are no plans a the moment to add the feature. Sorry. :-( My advice: for your situation, switch to listings (or break the lines manually).


10

When you add the color package and change morestring=[b]", into morestring=[b][\color{red}]", the attributes will color red. This will color the attributes red in your xml listings. \begin{lstlisting}[language=xml, frame=single] <xml> <person age="22" sex="female">Ann</person> </xml> \end{lstlisting} \documentclass{...


10

LaTeX already separates content from formatting. E.g. the look of \section{ABC} can be different depending on packages and classes. It is also easy to translate your XML-example in something more LaTeX-like e.g. \begin{timeline}{title=Australian History} \timepoint{year=60000BC,event=Aboriginal Migration,text=Aboriginal ...} \timepoint{...} \end{...


10

As described in your question the package listings can automatically break long lines. The is limited. The package breaks only on characters which are defined as others. To allow the break at every point you must say listings that a letter isn't a letter. This can be done be redefining the following definition: Original: \def\lst@lettertrue{\let\lst@...


9

ConTeXt can directly process XML. See Thomas's MyWay and the official documentation


9

The definition of a new command would be the easiest way to go. \newcommand*{\xml}[1]{\texttt{<#1>}} Use it in your document as \xml{tag}.


9

I don't know about the possible solutions with LaTeX and pdftex engine, but ConTeXt MkIV (which uses LuaTeX engine) supports an XML backend that is used to generate EPUB and tagged PDF. To get the XML output from a file, you need to add \setupbackend[export=yes] As an example, consider a simple file with some figures, math, and lists. \setupbackend[...


9

Try this code: \documentclass[12pt]{amsart} \usepackage{geometry} \usepackage{listings} \usepackage{color} \usepackage[usenames,dvipsnames,svgnames,table]{xcolor} \geometry{a4paper} \begin{document} This is a sample file: \lstset{ language=xml, tabsize=3, %frame=lines, caption=Test, label=code:sample, frame=shadowbox, ...


8

tex4ht can convert to XHTML and MathML. See my answer to this question.


8

Explanation: I am using twocolumns so you can see how the lines will break with each option (and how bad it can get). The first option (texttt) will produce the desired result since you have no characters to escape in the present case, but the line breaking will be messed up because TeX is not geared for this. The second option (\verb or verbatim ...


7

Do not put the XML path selector in the setup name: the \startxmlsetups ... \stopxmlsetups is just defining a command, not actually selecting items from the XML file. It is \xmlsetsetup that does the XML object selection. I am not a heavy user of ConTeXt's xml support myself, but I think you need something like this: \xmlsetsetup{}{xml:divGen[@type='toc']...


7

\sbox0{\lstinputlisting{example.xml}} \lstinputlisting[firstline=4,lastline=\the\numexpr\value{lstnumber}-5\relax]{example.xml} This save your input file in a box to count its lines number (so the file is not typeset in the document). This number is saved in the lstnumber counter so you can then use it to set your last line when you really insert the code. ...


7

Here is the general idea with the luaxml "package". \documentclass{article} \usepackage{luacode} \begin{luacode*} xml = require('luaxml-mod-xml') handler = require('luaxml-mod-handler') \end{luacode*} \begin{document} \begin{luacode*} sample = [[ <DATA> <NAME="name" /> <VERSION="1" /> <VARIABLES> <TEST> <...


7

If it is Document type definitions that you want, Pygments has support for it and produces a very neat output imo. For LaTeX documents you can harness it easily with the minted-package, e.g.: \documentclass{article} \usepackage{minted} \usemintedstyle{autumn} \begin{document} \begin{minted}{dtd} <!-- TEI P4 DTD. Generated 2004-07-15T16:23:29-04:00 ...


7

Suppose following input example: <?xml version="1.0" encoding="utf8"?> <cenik> <nazev>Počítačové komponenty</nazev> <platnost od="1.1.2000" do="31.3.2000"/> <dodavatel> <nazev>První hardwarová, s.r.o.</nazev> <adresa> <ulice>Průmyslová 12</ulice> <mesto>Praha ...


6

The minted package produces code which has tag-names, attribute-names, attribute-values and tag-contents printed differently, so the following code would produce the output which follows it: \documentclass{minimal} \usepackage{minted} \begin{document} \begin{minted}{xml} <xml> <person age="22" sex="female">Ann</person> </...


6

There is the DocBook XML format which you can use for books or other form of documentation. There is for example Apache FOP which can compile it to PDF. The advantage is that it can be converted to other formats like HTML much more easily than LaTeX. I know it from the Subversion book which is written in DocBook XML because the publisher O'Reilly Media wants ...


6

TeXnicCenter allows for the creation of "user text modules" that are initiated via a shortcut. To insert your own module, follow Insert>Own Text Modules>Manage Text Modules. Now you can enter a new one called (say) Separator: Once you've established the correct "before cursor" and "after cursor" combination, it is accessible via the menu selection: Or ...


6

You certainly can use XSLT to generate TeX from XML for typesetting. That is how the PDF version of the MathML spec is produced for example. however the details depend greatly on the XML vocabulary used for input (and of course on the typesetting requirements for output). If you don't want to literally use XML syntax in the input document, then many of the ...


6

I think there is also another way: LaTeXML: A LaTeX to XML Converter. After having install it, one might proceed as follows. Consider the following MWE called test_xml.tex: \documentclass[a4paper,11pt]{article} \usepackage{graphicx} \begin{document} Here is some text that precedes the image. \begin{figure} \includegraphics[scale=0.5]{ctan_lion} % http://...



Only top voted, non community-wiki answers of a minimum length are eligible