Skip to content
This repository was archived by the owner on Jun 8, 2026. It is now read-only.

Commit 027dc77

Browse files
committed
Fix invalid chars in tkinter
1 parent 59e6be8 commit 027dc77

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

pydetex/_gui_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ def _load_file() -> List[str]:
332332

333333
self._default_settings = {
334334
self.CFG_CHECK_REPETITION: (False, bool, [True, False]),
335-
self.CFG_FONT_SIZE: (11, int, self._valid_font_sizes),
335+
self.CFG_FONT_SIZE: (12 if ut.IS_OSX else 11, int, self._valid_font_sizes),
336336
self.CFG_LANG: ('en', str, self._lang.get_available()),
337337
self.CFG_LAST_OPENED_DAY: (ut.get_number_of_day(), int, lambda x: x >= 0),
338338
self.CFG_LAST_OPENED_FOLDER: ('/', str, lambda x: os.path.isdir(x)),

pydetex/_gui_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,11 @@ def insert_highlighted_text(self, s: str, clear: bool = False, font_format: bool
723723
self.clear()
724724
for t in ut.split_tags(s, list(fonts.FONT_TAGS.values())):
725725
tag, text = t
726-
self.insert('end', text, fonts.TAGS_FONT[tag] if font_format else 'normal')
726+
try:
727+
self.insert('end', text, fonts.TAGS_FONT[tag] if font_format else 'normal')
728+
except tk.TclError:
729+
chars = [text[j] for j in range(len(text)) if ord(text[j]) in range(65536)]
730+
self.insert('end', ''.join(chars), fonts.TAGS_FONT[tag] if font_format else 'normal')
727731

728732
def clear(self) -> None:
729733
"""

pydetex/_utils_tex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def __load_unicode() -> None:
679679
respath = str(os.path.abspath(os.path.dirname(__file__))).replace('\\', '/') + '/res/u_'
680680
for j in _TEX_TO_UNICODE.keys():
681681
if j == 'latex_symbols':
682-
with open(f'{respath}symbols.txt', 'r') as f:
682+
with open(f'{respath}symbols.txt', 'r', encoding='utf-8') as f:
683683
line = f.readline()
684684
while line != "":
685685
words = line.split()
@@ -688,7 +688,7 @@ def __load_unicode() -> None:
688688
_TEX_TO_UNICODE['latex_symbols'].append((code, val))
689689
line = f.readline()
690690
else:
691-
with open(f'{respath}{j}.txt', 'r') as f:
691+
with open(f'{respath}{j}.txt', 'r', encoding='utf-8') as f:
692692
line = f.readline()
693693
while line != '':
694694
words = line.split()

0 commit comments

Comments
 (0)