How much marijuana is really in that pot brownie? Chocolate can throw off potency tests so labels aren't always accurate, and now scientists are trying to figure out why.

In states where marijuana is legal, pot comes in cookies, mints, gummies, protein bars — even pretzels. These commercial products are labeled with the amount of high-inducing THC. That helps medical marijuana patients get the desired dose and other consumers attune their buzz.

But something about chocolate, chemists say, seems to interfere with potency testing. A chocolate labeled as 10 milligrams of THC could have far more and send someone to the emergency room with hallucinations.

The latest research on chocolate, to be presented at a San Diego meeting this week, is one example of chemistry's growing role in the marijuana industry. Besides chocolate's quirks, chemists are working on extending shelf life, mimicking marijuana's earthy aroma and making products safer.

The marijuana business is at a crossroads in its push for legitimacy. The federal government still considers marijuana illegal, yet more than 30 U.S. states allow it for at least medical use. Even in those states, there are no recognized standard methods for testing products for safety and quality.

Chemists working for marijuana companies and testing labs are developing those standards and some are legally protecting their ideas.

Scores of cannabis-related inventions have received U.S. patents, said Boston attorney Vincent Capuano, who holds a doctorate in organic chemistry. Inventors have patented ways of putting cannabis into milk, coffee pods, ice pops and chewing gum.

"There's a lot of flash and hipness, snake oil and marketing. But there's still a lot of real chemical advance happening," Capuano said of the industry. "It's right in center field for chemists."

Marijuana contains hundreds of chemicals, including cannabinoids such as THC and CBD, a trendy ingredient with unproven health claims. Some pose challenges when they're processed. Chocolate is a good example.

"The chocolate itself is affecting our ability to measure the cannabinoids within it," said David Dawson, chemist and lead researcher at CW Analytical Laboratories in Oakland, California, which tests marijuana.

The more chocolate in the vial, the less accurate the test results, he found. He thinks some of the THC is clinging to the fat in chocolate, effectively hiding from the test.

Dawson's research is on the agenda at the American Chemical Society meeting in San Diego. The conference includes 20 presentations about marijuana's technical challenges, said Markus Roggen, a Vancouver, British Columbia-based chemist organizing the program. That's a big change from a few years ago when presenters didn't get much beyond the basics such as: "This is THC. This is CBD."

Some in the marijuana industry hold "a mythical belief in the goddess of cannabis," Roggen said, but chemists view marijuana more objectively. For its part, the industry is learning to accept the "new guard of scientists with a different approach to the plant," he said.

Another focus of research is a group of chemicals called terpenes that give the marijuana plant its pungent aroma. Many terpenes get lost or changed in the process of making a THC or CBD extract. But users want a certain smell and taste, said chemist Jeffrey Raber.

Raber heads the Werc Shop, a Los Angeles company that mixes terpenes from lavender, oranges, black pepper and other plants to mimic the flavor and scent of cannabis varieties. The mashups are sold to companies who add them to oils, tinctures and foods.

Monica Vialpando, a San Francisco chemist, is working to prevent drinks with CBD and THC oils from separating into unappealing layers while sitting on the shelf. The oils don't dissolve in water, a problem for companies trying to create new drinks.

"We're fighting against the true nature of the THC," Vialpando, who came to cannabis from the pharmaceutical industry.

Chemists solve the problem by increasing the surface area of the oil particles and adding ingredients, called surfactants and emulsifiers, to prevent separation.

She said consumers should be skeptical of outrageous claims for edibles and beverages, including that all the THC or CBD in a product will be absorbed. Some potency will always be lost in the digestive system before it hits the bloodstream, she said.

But for now, exactly what happens in the human body with most of these products is unclear, Vialpando said, because there's been very little safety testing of cannabis emulsions in animals, much less in humans.

In Ottawa, Ontario, a Canadian government lab is working on a sensor to help police identify stoned drivers. The goal is to detect cannabinoid molecules in saliva or breath droplets, using light and nanoparticles. Still years away from roadside use, the technology might someday also be used by marijuana growers to determine the peak time to harvest, said chemist Li-Lin Tay, who leads the work for National Research Council of Canada.

To do his work with chocolate, Dawson grinds a THC-infused chocolate bar in a commercial food processor, weighs samples, adds solvent to the material ("It starts looking like chocolate milk," he says), before measuring the THC potency. He's tested cocoa powder, baking chocolate and white chocolate to try to determine what ingredients are hiding the THC during testing.

This will lead to better testing standards and safer products, he said.

"We need good 'capital S' science," he said.

Follow NBC HEALTH on Twitter & Facebook.