Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How is bad in the line 28 (AppendTo....)?

LATEX tell me that"missing $"

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8,latin1]{inputenc}
\usepackage{listings,xcolor}
%\usepackage{listingsutf8}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}

\input{listings-spa.tex}
\lstset{language=Mathematica}
\lstset{basicstyle={\sffamily\footnotesize},
  numbers=left,
  numberstyle=\tiny\color{gray},
  numbersep=5pt,
  breaklines=true,
  captionpos={t},
  frame={lines},
  rulecolor=\color{black},
  framerule=0.5pt,
  columns=flexible,
  tabsize=2
}

\begin{document}
%\lstset{inputencoding=utf8/latin1}
  \begin{lstlisting}[language=Mathematica,caption={Example code}]
  Do[Print["número=number -> ",i],{i,1,10}];

    AppendTo[bigstat, Last[x]](*    Añadimos la propuesta de solución del algoritmo Codicioso a la lista bistat donde almacenamos todas lassolcuiones propuestas en cada ejecución del mismo. *)    , {p, 1, simulaciones}  (\* Numero de simulaciones \*)
    ];

   Which[opneigh == 1, bigstatbestn2 = bigstat, opneigh == 2,
    bigstatbestn6 = bigstat];(* Almacenamos en bigstatn2,6 o t,
   TODOS los puntos que el algoritmo codicioso da como propuessta de \
solución en cada una de las simulaciones hechas
    La opción=1 indica que consideramos vecindarios de 2 vecinos;
   opción=2 vecindario de 6 vecinos; opcion=3,
   vecindarios de todos los vecinos *)
   Clear[bigstat](*
   Borramos bigstat dado que ya lo tenemos almacenado en la \
correspondiente lista para el analisis finales despues *)
   , {opneigh, 1, 2}
   ] ; (* 1.- con 2 vecinos    2.-con6 vecinos    *)

 Button[" Generar Simulacion", astart = ! astart],
 Style["Versión 1.35b", Darker@Blue, 12],
 Style["Mika Ike . m@gmail.com)", Blue,
  TextAlignment -> Right, 11]
 , ControlPlacement -> Right, Initialization -> (astart = True),
 TrackedSymbols :> {astart}]

  \end{lstlisting}
\end{document} 

listing-spa is to solve the problem af characters á, í, ñ, ...

https://www.dropbox.com/s/4mip8tkayotqpoj/listings-spa.tex from Tomas message How to insert code with accents with listings?

share|improve this question
    
Is this not basically the same question as tex.stackexchange.com/questions/185898/…, also by you? –  Christian Hupfer Jun 21 at 12:46
    
@ChristianHupfer No, it´s similar, but I´m deleting the other one. –  Mika Ike Jun 21 at 13:09

1 Answer 1

up vote 5 down vote accepted

UTF-8 is not supported by listings. Package listingsutf8 helps, but the code need to be stored in a file, e.g. example-mathematica.m:

  Do[Print["número=number -> ",i],{i,1,10}];

    AppendTo[bigstat, Last[x]](*    Añadimos la propuesta de solución del algoritmo Codicioso a la lista bistat donde almacenamos todas lassolcuiones propuestas en cada ejecución del mismo. *)    , {p, 1, simulaciones}  (\* Numero de simulaciones \*)
    ];

   Which[opneigh == 1, bigstatbestn2 = bigstat, opneigh == 2,
    bigstatbestn6 = bigstat];(* Almacenamos en bigstatn2,6 o t,
   TODOS los puntos que el algoritmo codicioso da como propuessta de \
solución en cada una de las simulaciones hechas
    La opción=1 indica que consideramos vecindarios de 2 vecinos;
   opción=2 vecindario de 6 vecinos; opcion=3,
   vecindarios de todos los vecinos *)
   Clear[bigstat](*
   Borramos bigstat dado que ya lo tenemos almacenado en la \
correspondiente lista para el analisis finales despues *)
   , {opneigh, 1, 2}
   ] ; (* 1.- con 2 vecinos    2.-con6 vecinos    *)

 Button[" Generar Simulacion", astart = ! astart],
 Style["Versión 1.35b", Darker@Blue, 12],
 Style["Mika Ike . m@gmail.com)", Blue,
  TextAlignment -> Right, 11]
 , ControlPlacement -> Right, Initialization -> (astart = True),
 TrackedSymbols :> {astart}]

The the TeX file looks like:

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{listingsutf8}
\usepackage[T1]{fontenc}
\usepackage[spanish]{babel}

\lstset{basicstyle={\sffamily\footnotesize},
  numbers=left,
  numberstyle=\tiny\color{gray},
  numbersep=5pt,
  breaklines=true,
  captionpos={t},
  frame={lines},
  rulecolor=\color{black},
  framerule=0.5pt,
  columns=flexible,
  tabsize=2,
}

\begin{document}
\lstinputlisting[
  language=Mathematica,
  caption={Example code},
  inputencoding=utf8/latin1,
]{example-mathematica.m}
\end{document}

Result

Remarks:

  • Two options do not make much sense for package inputenc. You cannot have two input encodings at the same time. An input encoding can be switched later by macro \inputencoding{<encoding option>}.
share|improve this answer
    
When I copy (Ctrl+C) from Mathematica, automatically appears \ at the end of long line comments. Is possible to delete it. I know that the important was solved! Thank you. –  Mika Ike Jun 21 at 16:09
1  
@MikaIke: I would clean up the source code in the first place: indenting, line length, spaces (consistent, after comma, ...). In the current form the code is quite unreadable. If the line length is limited without long lines, then the backslash problem would also be solved. –  Heiko Oberdiek Jun 21 at 16:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.