To compare the safety and effectiveness of an investigational drug therapy (trimetrexate plus leucovorin calcium) with that of conventional therapy (sulfamethoxazole-trimethoprim) in the treatment of moderately severe Pneumocystis carinii pneumonia (PCP) in patients who have AIDS, are HIV positive, or are at high risk for HIV infection. New treatments are needed to reduce the mortality rate from PCP in AIDS patients and to reduce the high relapse rate found after conventional therapy. Trimetrexate (TMTX) was chosen for this trial because it was found to be much more potent than sulfamethoxazole/trimethoprim (SMX/TMP) against the PCP organism in laboratory tests. Also TMTX, in combination with leucovorin (LCV), did not cause severe toxicity in a preliminary trial. It is believed that TMTX will be more effective in treating PCP and in preventing a recurrence of PCP.