Assuming the type of pen is ballpoint or similar. Most inks (not all) are soluble in alcohol. Isopropal Alcohol (Rubbing Alcohol) or Ethanol (Drinking type or Hand Sanitizer) will work. A good quantity rubbed into the stain followed by blotting with a paper towel then wash your trousers as you would normally.
I've had really good luck using a product called Amodex. It's designed for just that purpose of removing ink from fabric. I've ordered it online, but I'm guessing it is also available at fabric/craft stores.
I've had good results with soaking the cloth in whole milk, although I haven't tried it with jeans.
Hairspray sprayed directly on the fabric where the ink is, will instantly lift the ink right out... Then simply rinse with water... works like magic. I've used this trick for years and it has never failed me.