Python Forum
Super/subscript copied to word - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Super/subscript copied to word (/thread-472.html)



Super/subscript copied to word - lk89 - Oct-13-2016

Hiya! 
I'm making a code from which the output I want to be able to copy into word. A few of the letters/numbers need to be super/sub scripted and I used unicode for that, e.g.  
print(u'\u00B3')
which returns superscripted 3 as I want it to. However, when I copy it into Word, it looks superscripted but isn't actually so if you write the same text next to it in Word using the superscript there it looks different. As in the same document I will be writing things directly into Word and not copy from Python output I would like this to look the same. Does anyone have solutions to making super/sub script a different way so Word actually picks it up as that?
Cheers!


RE: Super/subscript copied to word - sparkz_alot - Oct-13-2016

Not entirely sure, but if I run
Quote:print('10' + u'\u00B3')
in the command terminal and also create the same thing (10^3) within Wordpad, I get the same result and they look identical.

If I run 
with open('test.rtf', 'w') as f:
   f.write('10' + u'\u00b3')
I again get the same result. The difference between the first and second methods was in the first instance, the default font is "Calibri", in the second, when double-clicked, the font is "Courier New". So you may have to ensure Python and Word are using the same font.


RE: Super/subscript copied to word - lk89 - Oct-13-2016

Yeah, I copy it into word and then write the same thing in word and then make both of them the same font and they're not the same. They look pretty similar-but still not the same. Also when you highlight the superscripted number it doesn't show that it is superscripted as normal superscripted numbers in Word would do if you know what I mean.
I'm probably being very fuzzy about it, but I'd just like it to be a superscripted format rather than a letter that looks superscripted.


RE: Super/subscript copied to word - snippsat - Oct-13-2016

(Oct-13-2016, 03:36 PM)sparkz_alot Wrote: you may have to ensure Python and Word are using the same font.
Or more correct this is about encoding ;)

There some difference if you Python 2 or 3.
Eg with Python 3 that have encoding build into open().
with open('test.txt', 'w', encoding='utf-8') as f:
   f.write('10' + u'\u00b3')
 
If you open this txt in word it should show up a box(File conversion) and it should have mark UTF-8.
Choose that and it look the same in word.

It's about choosing same encoding out and in,
and UTF-8 is an obvious first choice to try.


RE: Super/subscript copied to word - sparkz_alot - Oct-13-2016

The only other thing I can think of is in python, you are utilizing utf-8 code. Windows does not use utf-8 it uses 'code pages'. To be honest, I don't know how Word displays the super and sub scripts, but it may not be the utf-8 equivalent which is why you are seeing the slight variation?