Glam Prestige Journal

Bright entertainment trends with youth appeal.

The only answer I could look online was to use Ctrl+Shift+V but that answer was almost a decade old and doesn't work anymore. I'm trying to copy text from the Evince PDF reader into other applications (Anki or gedit) but that it usually shows up with formatting which is annoying.

By formatting, I meant that it copies the text while preserving it's original format. For example, if I copy this text from Evince.

enter image description here

And then try to paste it into another application, it shows up like this.enter image description here

What I'm trying to achieve is to paste in without the formatting (indentations in this case), to make it look somewhat like this.

Another Image

I'm on Ubuntu 21.10.

8

1 Answer

What you define as "formatting", i.e., newlines or white space because of spaces or tabs, is not formatting. These are represented by characters such as carriage returns, space characters or tab characters.

When pasting to gedit or to the terminal, these characters are preserved. Formatting codes that may be included by word processors are not preserved.

Your only option is to change the text before pasting it in the destination. In the text editor, you can replace tabs, multiple spaces, line feeds. This being Linux, it could also be automated (with thanks to Lumo for the link).

A script that can do this boils down to:

#!/bin/bash
SelectedText="$(xsel)"
ModifiedText="$(echo "$SelectedText" | \ sed 's/\.$/.|/g' | sed 's/^\s*$/|/g' | tr '\n' ' ' | tr '|' '\n')"
echo "$ModifiedText" | xsel -bi

First line copies current text in the clipboard to the clipboard. Second line modifies it (in this script, only new lines are addressed, no spaces or tabs), third line puts the result back in the clipboard, ready to paste.

Place such script in your ~/.local/bin, make it executable then bind it to a shortcut key. After copying text from a PDF, remember to hit that shortcut key before pasting.

Current example will only work on Xorg. Ubuntu 21.10 defaults to Wayland. xclip or xsel do not work on Wayland so should be replaced with wl-copy and wl-paste from the wl-clipboard package.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy