Python Forum
Super/subscript copied to word
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Super/subscript copied to word
#1
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!
Reply
#2
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
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.
Reply
#4
(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.
Reply
#5
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?
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problems with super() Hoespilaar 2 271 Apr-10-2024, 10:10 AM
Last Post: Hoespilaar
  super() in class akbarza 1 476 Dec-19-2023, 12:55 PM
Last Post: menator01
  Error in Int object is not subscript-able. kakut 2 1,191 Jul-06-2022, 08:31 AM
Last Post: ibreeden
  How can I find the value of k(subscript t+1) for periods t=1...50? maeva 2 1,578 Nov-07-2021, 07:59 AM
Last Post: maeva
  Why changing data in a copied list changes the original list? plumberpy 3 2,253 Aug-14-2021, 02:26 AM
Last Post: plumberpy
Question Problem: Check if a list contains a word and then continue with the next word Mangono 2 2,522 Aug-12-2021, 04:25 PM
Last Post: palladium
  Error in Int object is not subscript-able. How to debug this ? yanDvator 1 2,240 Aug-03-2020, 02:28 PM
Last Post: Larz60+
  superclass and super() grkiran2011 1 1,752 Jun-20-2020, 04:37 AM
Last Post: deanhystad
  Python Speech recognition, word by word AceScottie 6 16,036 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  word subscript Staph 1 1,790 Mar-31-2020, 10:21 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020