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.

I want to use inline TikZ code to create my own subscript symbol. For example something like

$V_{\tikz{ \draw [|->] (0,0) -- (2ex,0); }}$

The problem is that it is not scaled. The length of the arrow is longer than 2 times the character x (ex means the height of character x). How can I fix this? The problem becomes really painful, if the symbol is a subscript of a subscript. TikZ doesn't scale the symbol although the absolute height of ex changes.

I don't want to use a 'standard' math symbol. Actually, my symbol is more complicated and no mathematical symbol is available.

share|improve this question
1  
You can start with using em instead of ex. Also arrow head size is often related to the line width hence you can also make it depend on the font size. Something like $V_{\tikz[line width=1/3em]{\draw[|->] (0,0) -- (0.5em,0);}}$ –  percusse Apr 1 '13 at 16:37
    
Thx for your help but it won't work. Here an example: $V_{\tikz[line width=1/3em]{\draw[|->] (0,0) -- (0.5em,0);}}$ $\frac{1}{V_{\tikz[line width=1/3em]{\draw[|->] (0,0) -- (0.5em,0);}}}$ "V" is scaled properly but not the Tikz symbol. –  user4811 Apr 1 '13 at 16:49
2  
You can use amsmath’s \text macro to get the correct scaling of the font units (em and ex), still the line width is fixed and so are the arrows (including some fixed lengths like 2pt). I think one need to declare new arrows that are based on font units or scale the resulting \tikz with \resizebox and \mathchoice or \mathpalette. –  Qrrbrbirlbel Apr 1 '13 at 16:52
    
Could you show your “actual symbol”? Maybe there is a better choice than using TikZ. –  Qrrbrbirlbel Apr 1 '13 at 16:57
    
@Qrrbrbirlbel: This was the solution. The inline Tikz code must be encapsulated by "\text{}" for correct scaling. I have drawn the arrow head with a simple filled, triangle node. It works like a charm and looks great! Thx!!! –  user4811 Apr 1 '13 at 19:03
add comment

1 Answer

The macro \text from the amstext (also loaded by amsmath) package sets up the correct font sizes and can used to correctly access the font units em and ex.

From your comments, it seems as if you have used font-size-based nodes for the arrows instead of using real arrows (which is probably not a bad idea because TikZ is very inflexible when it comes to arrow sizes), however I have included a small redefinition of the | arrow tip that takes one option (set with \pgfsetarrowoptions and accessed with \pgfgetarrowoptions).

Code

\documentclass{article}
\usepackage{tikz,amstext}
\makeatletter
\newcommand*{\myarrow}{%
    \mathchoice
        {\pgfsetarrowoptions{:}{2pt}\my@arrow}
        {\pgfsetarrowoptions{:}{2pt}\my@arrow}
        {\pgfsetarrowoptions{:}{1pt}\my@arrow}
        {\pgfsetarrowoptions{:}{1pt}\my@arrow}
}
\newcommand*{\my@arrow}{\text{\tikz\draw[:->] (0,0) -- (2ex,0);}}
\pgfarrowsdeclare{:}{:}
{
  \pgfarrowsleftextend{+-0.25\pgflinewidth}
  \pgfarrowsrightextend{+.75\pgflinewidth}
}
{
  \pgfutil@tempdima\pgfgetarrowoptions{:}
  \advance\pgfutil@tempdima by0\pgflinewidth%
  \pgfsetdash{}{+0pt}
  \pgfsetrectcap
  \pgfpathmoveto{\pgfqpoint{0.25\pgflinewidth}{-\pgfutil@tempdima}}
  \pgfpathlineto{\pgfqpoint{0.25\pgflinewidth}{\pgfutil@tempdima}}
  \pgfusepathqstroke
}
\makeatother
\begin{document}
$\displaystyle\myarrow\textstyle\myarrow V_{\myarrow_{\myarrow}}$
\end{document}

Output

enter image description here

share|improve this answer
add comment

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.