Graphics, Figures & TablestikZ | Compilation fails for Documents in Spanish

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
xetam
Posts: 4
Joined: Wed May 02, 2012 7:22 pm

tikZ | Compilation fails for Documents in Spanish

Post by xetam »

Hi,

I tried to add a caption in a figure with tikZ in a margin note but LaTeX show many errors when compiling but this no occurs with i setup a document with English language and i need setup with Spanish.

Code: Select all

\documentclass[11pt]{article} 

\usepackage{graphicx}											
\usepackage{caption}											
\usepackage[paperwidth=8.5in, paperheight=11in]{geometry}
\geometry{top=0.75in,left=0.9in,bottom=0.75in,textwidth=5in, marginparsep=0.3in,marginparwidth=2in}								
\usepackage[spanish]{babel}
\usepackage[utf8]{inputenc}

\usepackage{tikz}
\usepackage{marginnote}
\begin{document}
\marginnote{
\begin{tikzpicture}[scale=2]
\draw [thick](0,0) -- (1.75,1.75);
\draw[red,very thick,->,>=latex] (0,0) -- (.75,.75)node[below=3pt] {$-F$};
\draw[red,very thick,<-,>=latex] (1,1)node[anchor=west] {$F$} -- (1.75,1.75);
\draw [|<-,>=latex] (-0.2,0.2) -- (0.55,.95);
\draw [->|,>=latex](.75,1.15) -- (1.55,1.95) ;
\shade[ball color=green] (0,0) circle (.05cm) node[below=3pt] {$M$} ;
\shade[ball color=green] (1.75,1.75) circle (.05cm) node[right=3pt,anchor=west] {$m$} ;
\coordinate [label=left:{$r$}] (A) at (.75,1.1);
\end{tikzpicture}
\captionof{figure}{text example}
}
\end{document}
Last edited by Stefan Kottwitz on Fri May 04, 2012 3:22 pm, edited 1 time in total.
TexLive 2011
Texmaker
windows 7 64

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Compilation fails for Documents in Spanish

Post by Stefan Kottwitz »

Hi,

welcome to the board!

The reason for the error is, that the character > has a special meaning for spanish texts with babel, it's a shortcut for quoting, but you use it for TikZ arrow tips. You can disable the shortcut, if you like, then the error would go away. Just write after \begin{document}:

Code: Select all

\shorthandoff{>}
Stefan
LaTeX.org admin
xetam
Posts: 4
Joined: Wed May 02, 2012 7:22 pm

Re: tikZ | Compilation fails for Documents in Spanish

Post by xetam »

thankyou, run fine but i ask me but how this affects the text of document
TexLive 2011
Texmaker
windows 7 64
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Compilation fails for Documents in Spanish

Post by Stefan Kottwitz »

Do you use > as a shortcut for Spanish quoting, such as in >>? If not, disabling doesn't affect the document. Actually, the Spanish support affects the document, as you can see. Similar for <, by the way.

Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

tikZ | Compilation fails for Documents in Spanish

Post by cgnieder »

You can use etoolbox's \AtBeginEnvironment to patch the tikzpicture. Then you won't have to worry about effects on the text.

Code: Select all

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{tikz}
\usepackage{etoolbox}
\AtBeginEnvironment{tikzpicture}{\shorthandoff{>}\shorthandoff{<}}
\begin{document} 

<<prueba>>

\begin{tikzpicture}
 \draw[->] (0,0) --++ (2,0);
\end{tikzpicture}

<<otra prueba>>

\end{document}
babel_spanish_tikz.png
babel_spanish_tikz.png (2.84 KiB) Viewed 3915 times
Regards
site moderator & package author
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

tikZ | Compilation fails for Documents in Spanish

Post by Stefan Kottwitz »

Hi Clemens,

that's a very good tip, just in this case, where \marginnote is used, it would not directly work this way. Patching \@mn@@@marginnote perhaps would. ;)

Stefan
LaTeX.org admin
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

tikZ | Compilation fails for Documents in Spanish

Post by cgnieder »

Oh, I didn't test for that... Thanks Stefan!

It turned aut to be a bit trickier, actually. The code below will disable the shorthands in \marginnote and the tikzpicture:

Code: Select all

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{tikz,marginnote}
\usepackage{etoolbox}

\makeatletter
\renewcommand\marginnote{%
  \shorthandoff{>}\shorthandoff{<}\@dblarg\@mn@marginnote}
\apptocmd\@mn@@@marginnote{\shorthandon{>}\shorthandon{<}}{}{}
\makeatother
\AtBeginEnvironment{tikzpicture}{\shorthandoff{>}\shorthandoff{<}}

\begin{document} 

<<prueba>>
\marginnote{
\begin{tikzpicture}
 \draw[->] (0,0) --++ (2,0);
\end{tikzpicture}
}
\begin{tikzpicture}
 \draw[->] (0,0) --++ (2,0);
\end{tikzpicture}

<<otra prueba>>

\end{document}
Best
site moderator & package author
Post Reply