| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package HEP::Names::LaTeX; | ||||||||||
| 5 | 1 | $HEP::Names::LaTeX::VERSION = '0.01'; | |||||||||
| 6 | # ABSTRACT: formats plain names of high energy physics (HEP) particles to LaTeX | ||||||||||
| 7 | |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Exporter qw( import ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | our @EXPORT = qw( particle_to_latex ); | |||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 1 | my $names_to_escape = qr(psi|upsilon|gamma|tau|rho|pi|mu|eta|nu|omega); | |||||||||
| 15 | |||||||||||
| 16 | sub particle_to_latex | ||||||||||
| 17 | 10 | ▶ | { | ||||||||
|
Subroutine
particle_to_latex: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||
| 18 | 10 | ▶ | return '' unless @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | |||||||||||
| 20 | # in case of string literal in argument, we cannot modify @_! | ||||||||||
| 21 | 10 | my @names = @_; | |||||||||
| 22 | 10 | foreach my $name ( @names ) { | |||||||||
| 23 | |||||||||||
| 24 | 12 | my ( $charge, $has_apo ) = ( '', '' ); | |||||||||
| 25 | # this probably should be done better :) | ||||||||||
| 26 | 12 | my $is_anti = $name =~ s/^anti-//; | |||||||||
| 27 | # charge is at last position (plus *) | ||||||||||
| 28 | 12 | ▶ | $charge = $1 if $name =~ s/(\**[0+-]+$)//; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 12 | ▶ | $has_apo = $1 if $name =~ s/('+)//; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | 12 | ▶ | my $subscript = $1 if $name =~ s/_(.*)$//; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | |||||||||||
| 32 | 12 | my $total_charge = $has_apo.$charge; | |||||||||
| 33 | #$total_charge = undef unless length( $total_charge ) | ||||||||||
| 34 | |||||||||||
| 35 | # escape greek names | ||||||||||
| 36 | 12 | $name =~ s/($names_to_escape)/\\$1/gi; | |||||||||
| 37 | 12 | ▶ | $subscript =~ s/($names_to_escape)/\\$1/gi if $subscript; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 38 | |||||||||||
| 39 | # ad put it together | ||||||||||
| 40 | 12 | ▶ | $name = "\\bar{$name}" if $is_anti; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 41 | 12 | ▶ | $name = $name."_{$subscript}" if $subscript; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | 12 | ▶ | $name = $name."^{$total_charge}" if length($total_charge); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 12 | $name = "\$".$name."\$"; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 10 | ▶ | return wantarray ? @names : $names[0]; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 1 | 1; | |||||||||
| 51 | |||||||||||
| 52 | __END__ | ||||||||||