A man accused of plotting a terrorist attack on a passenger train spent most of what was supposed to be a quick, procedural court appearance ranting about a strip search and gay marriage.

Chiheb Esseghaier, 31, one of two men charged in the alleged Via Rail plot, began the hearing by complaining that he had just been subjected to a strip search and "forced to show my sex."

He suggested that if a guard at the court thought he had contraband smuggled in from jail, it was an indictment of the justice system.

"When you don't have confidence between each other and you doubt each other, then your system is weak," Esseghaier told the judge.

"From where I would get the weapon? From where would I get the drug? I have been in my cell for the past nine months."

Superior Court Judge John McMahon patiently explained that there are many such cases, but it wasn't long before Esseghaier began butting heads with the judge.

Esseghaier has often used court appearances to rant about the Criminal Code, saying he refuses to be judged by it because it was created by humans, not God, and is therefore imperfect.

But Wednesday marked the first time the case had come before McMahon.

The judge allowed Esseghaier, who is unrepresented, to rant for a few minutes before suggesting several times it would be in the accused terrorist's best interests to get a lawyer.

Esseghaier bristled at that, shouting "Excuse me" at the judge.

"You interrupted me and I want to be able to finish," Esseghaier said.

"The Criminal Code, as I said, is written by humans...we are putting the laws of God behind our back and are following the laws of humans."

Esseghaier began gesturing forcefully toward the guards, the lawyers and those observing the hearing, as if giving a lecture, and launched into an anti-gay marriage rant.

He appeared to be suggesting that because the Criminal Code does not prohibit gay marriage it goes against the laws of God and is, in his eyes, not valid.

McMahon tried to cut in and when Esseghaier shouted at him again the judge told him his opinions about the Criminal Code were not relevant to the day's proceedings.

Esseghaier and his co-accused, Raed Jaser, are set to return to court Feb. 21 in front of a different judge to set a case management schedule.

Jaser, 36, who is represented by lawyer John Norris and was denied bail in November, said nothing during the hearing.

The permanent resident of Palestinian descent faces four charges, including conspiracy to murder for the benefit of a terrorist group.

Esseghaier, a Tunisian national doing doctoral research on nanosensors, is facing five charges, including participating in a terrorist group.

The duo was arrested in April and is accused of plotting to attack a train that travels from New York City to Ontario.