Tell me more ×
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.

When trying to pass name to \label I'm getting 'bad character' error. Is it possible to use \label like this, or should I just manually specify it outside of \img macro?

% Usage: \img[name]{caption}
\newcommand{\img}[2][image]{%
    \begin{figure}[H]
        \includegraphics[width=\textwidth]{img/#1.png}
        \caption[Long caption]{#2}
        % and here it says: bad character in label
        \label{#1}
    \end{figure}
}

Example call:

% some text
See example ~\ref{main.char}

% image itself
\img[main.char]{Chart example}

I'm using xelatex and the document compiles, but the reference to specified label does not work. It's lacheck that gives me that error and the document actually compiles - but the reference does not work. So, I assume that there's really an error.

Resolved: recompiled document twice in row, reference now works as it should.

share|improve this question
3  
Welcome to TeX.sx! What do you use for the filename #1? A complete minimal working example (MWE) would be helpfull ... – Kurt Oct 3 '12 at 14:58
1  
This looks ok to me. Without a complete example it will be difficult for anyone to help you. – Ian Thompson Oct 3 '12 at 15:01
Are you running lacheck on the document and receiving this error? Not sure how old or reliable it is since the archive on CTAN is dated 1998. This compiles under pdfLaTeX (or any compiler for that matter, I'm sure). The "bad character error" could stem from a space in your \label, but that shouldn't cause a compiler error. Regardless, it's best to not use spaces in labels or filenames. – Werner Oct 3 '12 at 15:04
Yes, it's lacheck that gives me that error and the document actually compiles - but the reference does not work. So, I assume that there's really is error. – Xifax Oct 3 '12 at 15:23
1  
What do you get as a reference, ??? Did you compile at least twice? – Werner Oct 3 '12 at 15:47
show 1 more comment

closed as too localized by lockstep, egreg, Martin Schröder, Mark S. Everitt, cgnieder Oct 4 '12 at 15:44

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.