Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

print comma in superscript

by qingfengzealot (Initiate)
on Apr 09, 2013 at 01:07 UTC ( #1027615=perlquestion: print w/replies, xml ) Need Help??
qingfengzealot has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Monks I wonder if there is any way to print a superscript comma. I've tried Unicode::Subscript, but there is no way to get the comma in a superscript way. Anyone can help me? Thanks very much. Best regards, QY

Replies are listed 'Best First'.
Re: print comma in superscript
by Your Mother (Bishop) on Apr 09, 2013 at 01:55 UTC

    Is there a superscript comma? I donít see one in here: Unicode subscripts and superscripts. I have no idea of some combining characters would allow for it. Printing the simple characters from the blocks in that link is pretty simpleĖ

    perl -CSD -e 'print " x" . chr($_) for 0xB2, 0xB3, 0x2070 .. 0x207F; print $/'
     x≤ x≥ x⁰ xⁱ x⁲ x⁳ x⁴ x⁵ x⁶ x⁷ x⁸ x⁹ x⁺ x⁻ x⁼ x⁽ x⁾ xⁿ
      Yes, I also cannot find a superscript comma in Unicode subscripts and superscripts. I think there should be a way to print this in PERL, whatever modules, if it works, please let me know. Thanks.
Re: print comma in superscript
by hdb (Monsignor) on Apr 09, 2013 at 06:30 UTC

    There is which is useful in this context. I compiled a small example, which creates a file super.rtf that has superscripts with commata.

    use strict; use warnings; use RTF::Writer; my %authors = ( "Isheng J. Tsai" => "1,2", "Magdalena Zarowiecki" => "1", "Nick Riddiford" => "14,15", ); my $rtf = RTF::Writer->new_to_file( "super.rtf" ); $rtf->prolog( title => "Authors" ); $rtf->paragraph( \'', "The authors:" ); for my $a (sort keys %authors) { $rtf->print( \'\plain', "$a" ); $rtf->print( \'\super', $authors{$a} ); $rtf->print( \'\plain', "," ); } $rtf->close;
Re: print comma in superscript
by GrandFather (Sage) on Apr 09, 2013 at 01:29 UTC
    print "<sup>,</sup>\n";

    works for me, but maybe that isn't what you want. Maybe you need to give us more context?

    True laziness is hard work
Re: print comma in superscript
by ww (Archbishop) on Apr 09, 2013 at 01:58 UTC

    Is there any chance you're actually looking to print an apostrophe... which, in some fonts, looks something like a "superscript comma"?

    If you didn't program your executable by toggling in binary, it wasn't really programming!

      Hi, I'm definitely looking for "superscript comma" rather than an apostrophe. It is commonly used in the authorship list for publications. We have hundreds of scientists with different affiliations, I want to use script to generate them instead of manually type them one by one. Now, I'm using PERL script to read from ".csv" and write to a ".rtf" file. Something like the author list in the following article: Sorry, I don't know how to upload a picture. If you cannot open this article, please let me know you email address and I can send it to you. I also attached my script here, hope someone can help me. Thanks very much.
      #!/usr/bin/perl -w use strict; use warnings; use RTF::Writer; use Unicode::Subscript ':all'; use Text::CSV; #use Unicode::Subscript qw(subscript superscript); if(@ARGV != 2) { print STDERR "Usage: input(.csv) output(.rtf)\n" +; exit(0); } my ($inf, $outf)=@ARGV; my $all_affi; my %hash; my @all_name; my $count=1; my @rows; my $csv = Text::CSV->new ( { binary => 1 } ) # should set binary attr +ibute. or die "Cannot use CSV: ".Text::CSV->error_diag (); open my $fh, "<", $inf or die "$inf: $!"; while ( my $row = $csv->getline( $fh ) ) { if($row->[0]=~/^\d/){ my @a_num; for(my $i=3; $i<=7; $i++){ if($row->[$i]=~/\w/){ my $tmp=$row->[$i]; if(! exists $hash{$tmp}){ $hash{$tmp}=$count; push(@a_num, $hash{$tmp}); $all_affi.=$count.$tmp."\. "; $count++; } }else{ last; } } my $a_num=join"\+", @a_num; if($row->[2]=~/\w/){ push(@all_name, "$row->[1] $row->[2]".superscript($a_num)) +; }elsif($row->[1]=~/\w/){ push(@all_name, "$row->[1]".superscript($a_num)); }else{ print STDERR "Error! Wrong first name for this row:\n$row\ +n"; exit; } } } $csv->eof or $csv->error_diag(); close $fh; my $all_name=join", ", @all_name; print STDERR "There are ". scalar(@all_name)." authors and ".scalar(ke +ys %hash)." affiliations in this list.\n"; my $final= "$all_name\n\n$all_affi\n"; #my $test='This algorithm is O(n' . superscript(3) . ')'; my $rtf = RTF::Writer->new_to_file($outf); $rtf->prolog( 'title' => "Greetings, Naomi" ); $rtf->number_pages; $rtf->paragraph( $final ); $rtf->close;

        I believe those characters you are thinking of as superscripts in the pdf document are actually just regular characters being displayed in a different font and different baseline. See this short discussion from stackoverflow. So you won't be able to get all the information into the plain text, instead you'll have to somehow encode the proper font formatting to send along with the text. Presumably the 'font' method in RTF::Writer might help do the job. But other monks may have better ideas.

        I should mention that there is no need to rely on ".rtf" file. If there are any ways to generate the authorship list (including the superscrtipt comma) and could let me copy the context to microsoft word (.doc) file, it would be fine... Whatever format the output is... Thanks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1027615]
Approved by ww
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2018-06-18 20:12 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.