How to open different plain text files (.txt and .tex) with different default applications?

You can try manually modifying the mimeapps.list file which contains all custom file associations.

This file can be found in ~/.local/share/applications or ~/.config (I'm using Ubuntu 20.04 and the file is in ~/.config. I'm not sure about 18.04, though).

Here is how you can proceed:

  1. Find the name of the desktop entry for your Texmaker program:

    Run this command in a terminal:

    ls /usr/share/applications | grep -i tex
    

    Look at the output and find something like:

    texmaker.desktop
    
  2. Open the mimeapps.list file with a text editor. You will see something like this:

    [Default Applications]  
    audio/mpeg=vlc.desktop
    image/jpeg=qView.desktop
    
    [Added Associations]
    audio/ogg=vlc.desktop;celluloid.desktop;
    
  3. Add the following line to the [Default Applications] part:

    text/x-tex=texmaker.desktop
    

    The part would then look like this:

    [Default Applications]  
    audio/mpeg=vlc.desktop
    image/jpeg=qView.desktop
    text/x-tex=texmaker.desktop
    
  4. Save the file and you're done (remember to change texmaker.desktop to the name that you found).

For reference, the line for .txt files will be something like:

text/plain=org.gnome.gedit.desktop