GeneralString to number

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ihiribar
Posts: 4
Joined: Wed Mar 10, 2010 5:30 pm

String to number

Post by ihiribar »

Hi!

From the package feynmf i get stringvalues like 'v1' and 'v2'.... 'vN' which represent points in a feynmangraph. I know how to implement \DrawLeftBentLine... my problem is to convert a string into an integernumber.

i want to draw lines by

Code: Select all

\newcommand{\bentline}[2]{
     \ifthenelse{\BehindSubString{v}{#1}<\BehindSubString{v}{#2}}{
           \DrawLeftBentLine
      }{
           \DrawRightBentLine
      }
}
i want to call this by:

Code: Select all

\bentline{v1}{v2} ... .draws the leftbentline
\bentline{v2}{v1} ... draws the rightbentline
But i cannot compare two strings with "<" and ">". i have to convert them to numbers... how do i do this?
Can anybody help?

A minimum example:

Code: Select all

\documentclass{article}
\usepackage{substr,ifthen}

\begin{document}
First: \BehindSubString{v}{v1} %First: 1
Second: \BehindSubString{v}{v2} \\ %Second: 2
Test: \ifthenelse{ 1<2}
        {Even permutation}
        {Odd permutation} %Test: Even permutation
%Next line produces error: 
Result: \ifthenelse{ \BehindSubString{v}{v1}<\BehindSubString{v}{v2}} 
        {Even permutation}
        {Odd permutation}
\end{document}
The error message is

Code: Select all

! Illegal parameter number in definition of \@gtempa.
<to be read again> 
                   2
l.10 ...dSubString{v}{v1}<\BehindSubString{v}{v2}}

P.S.: \BehindSubString is part of the substr package and gets the part behind substring (so the calls above return 1 and 2 respectively but as text not as number)
Last edited by ihiribar on Fri Mar 12, 2010 3:00 pm, edited 1 time in total.

Recommended reading 2024:

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

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

ihiribar
Posts: 4
Joined: Wed Mar 10, 2010 5:30 pm

String to number

Post by ihiribar »

Ok, maybe this is too complicated to do. but is there any other useful way to have a function do something like

Code: Select all

\LeftOrRight{v3}{v5} %writes the word "left"
\LeftOrRight{v1}{v3} %also write the word "left"
\LeftOrRight{v5}{v4} %write the word "right" (because 5>4)
\LeftOrRight{v2}{v1} %write the word "right" (because 2>1)
I believe that this should be possible somehow. But i have no idea how to do it. Please help
User avatar
nlct
Posts: 276
Joined: Thu Nov 06, 2008 11:15 am

String to number

Post by nlct »

You could try something like:

Code: Select all

\documentclass{article}

\usepackage{ifthen}

\def\extract#1#2\relax{#2}
\newcommand{\LeftOrRight}[2]{%
  \ifthenelse{\extract#1\relax<\extract#2\relax}{Left}{Right}%
}

\begin{document}

\LeftOrRight{v3}{v5}
\LeftOrRight{v1}{v3}
\LeftOrRight{v5}{v4}
\LeftOrRight{v2}{v1}

\end{document}
Regards
Nicola Talbot
ihiribar
Posts: 4
Joined: Wed Mar 10, 2010 5:30 pm

Re: String to number

Post by ihiribar »

Thank you that was exactly what i needed. :D
Post Reply