Forum How do I...?

Squared symbol

someuser
How do I get a squared symbol to show up? I've tried escaping it but it just comes up with my escape sequence rather that the character my escape sequence represents.
mikeday
By the "squared symbol" do you mean this: ² which is U+00B2, SUPERSCRIPT TWO?

You can reference this character in an XML/HTML document using a character entity, such as ² (hexadecimal) or ² (decimal).

In a CSS style sheet you can refer to it like this:
span { content: "\B2"; }

Note that the current font family must contain a glyph for this character, otherwise it will come out as a question mark in the PDF file.
someuser
Yes, that is the symbol I mean. And I have tried replacing the symbol with both the hexadecimal and decimal equivalent but they just show up in plain text - ie it shows up as ² or &#178 ; rather than the actual symbol.
mikeday
That's odd, are you editing the document in a regular text editor? The only thing that would stop an entity from expanding is if it is inside a CDATA section. Could you post a sample of your document?
erelsgl
why not use
<sup>2</sup>

?
someuser
I don't just use <sup>2</sup> because I have the same problem with all characters I need to escape (plus I don't know what <sup></sup> does :) ).

I use programmers notepad to edit the document. Here is some code. Prince is called from a p_erl cgi script.
#escaping function
sub utfcheck {
	my $string = $_[0];
	
	$string =~ s/–/-/gs;	
	$string =~ s/–/&mdash;/gs;
        $string =~ s/—/&mdash;/gs;
	$string =~ s/†/&dagger;/gs;
	$string =~ s/Ω/&Omega;/gs;		
	$string =~ s/&/&amp;/gs;
	$string =~ s/>/&gt;/gs; 
	$string =~ s/</&lt;/gs; 
	
	$string =~ s/([\x7f-\xff])/"&#" . ord($1) . ";"/eg; 
	
	
	return $string;
}

#excerpt from code that calls prince
print PRINCE "<tr>\n";
print PRINCE "<td>";
print PRINCE utfcheck($BOMrow->{'designator'});
print PRINCE "</td>\n";
print PRINCE "<td>\n";
print PRINCE utfcheck($BOMrow->{'description'});
print PRINCE "</td>\n"


No, the text is not inside a CDATA section, at least not that I put there!

Let me know if you need more code.
mikeday
That code looks okay to me, at least it seems to turn the squared character into &#178 which is certainly correct.

However, you really need to save the generated HTML document and see what the looks like to see why the characters are not being escaped correctly. If you can post an example document that you have generated in which the characters are not escaped properly that would be very helpful.
someuser
Fixed the problem, the code was escaping the "&" :oops:. Thanks for your help!