def rstdim_to_latexdim(width_str):
 match = re.match('^(\\d*\\.?\\d*)\\s*(\\S*)$', width_str)
 if (not match):
  raise ValueError
 res = width_str
 (amount, unit) = match.groups()[:2]
 float(amount)
 if (unit in ('', 'px')):
  res = ('%s\\sphinxpxdimen' % amount)
 elif (unit == 'pt'):
  res = ('%sbp' % amount)
 elif (unit == '%'):
  res = ('%.3f\\linewidth' % (float(amount) / 100.0))
 return res

def rstdim_to_latexdim ( width_str ) : match = re . match ( '^(\\d*\\.?\\d*)\\s*(\\S*)$' , width_str ) if ( not match ) : raise ValueError res = width_str ( amount , unit ) = match . groups ( ) [ : 2 ] float ( amount ) if ( unit in ( '' , 'px' ) ) : res = ( '%s\\sphinxpxdimen' % amount ) elif ( unit == 'pt' ) : res = ( '%sbp' % amount ) elif ( unit == '%' ) : res = ( '%.3f\\linewidth' % ( float ( amount ) / 100.0 ) ) return res
convert width_str with rst length to latex length .